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)
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
v1.2 - Added .remove()
and .remove_all()
methods