Code Monkey home page Code Monkey logo

badsql's Introduction

badsql

This is a file-based version of SQL.

badsql is only for Python scripts. For the terminal version, see badsql-tools.

Pass the headers as the parameter to db()

mydb = db(['id', 'name', 'age'])

Use .insert(pos, row) to add to the table

mydb.insert(1, [0, 'Bob', 11])
mydb.insert(2, [1, 'Sam', 9])
mydb.insert(3, [2, 'Will', 10])

Use .display() to show the table

print('Full table:\n')
mydb.display()
print('\n')

Use .select(query) to select specific rows

print('Where age >= 10:\n')
mydb.select('age >= 10').display()
print('\n')

Any Python-compilable code can be used

print('Where len(name) != 4:\n')
mydb.select('len(name) != 4').display()
print('\n')

The .select() method returns a db object

To save the table use .save(filename)

mydb.save('table')

To load in a table from a file use load(filename)

db2 = load('table')

This returns a db object

print('Loaded from table.csv:\n')
db2.display()

Note:

for .save() and load(), '.csv' is appended at the end of the filename

Other methods:

This removes the first instance of [2, 'Will', 10]

mydb.remove([2, 'Will', 10])

Similarly mydb.remove_all([2, 'Will', 10]) removes all the instances of [2, 'Will', 10]

.delete(x) removes the row in position x

mydb.delete(1)

Changes

7th April 2022

v0.1 - Initial release

v0.2 - Bug fix in _init_.py

v0.3 (now deleted) - Added README.md

v1.0.1 - Bug fix in setup.py

v1.1 - All bugs fixed, available for use with pip install badsql

8th April 2022

v1.2 - Added .remove() and .remove_all() methods

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.