Skip to content
/ sqlib Public

Wrapper for sqlite3, to easily handle your data.

License

Notifications You must be signed in to change notification settings

LiBa001/sqlib

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sqlib

Sqlib is a wrapper for a simple handling of sqlite3 databases, so you don't have to use sqlite statements anymore. You can easily handle your database by instances of the tables.

Sqlib doesn't provide full sqlite possibilities and it can only be used for one database.

Examples

Frame

from sqlib import *

connect("company.db")  # set db file (default is ':memory:')

employees = Table('employees')  # create an instance for your table

Insert

employees.insert({'firstname': 'Linus', 'lastname': 'Bartsch'})  # manage the data easy without sqlite

Get

Get one row:

employees.get('id', 1337)

Receive dictionaries instead of tuples:

{"id": 1337, "firstname": "Linus", "lastname": "Bartsch"}

Fetch more than one row and return only one column

employee.get('lastname', 'Johnson', fetch='all', only_column='firstname')  # 'fetch' can also be an integer
['John', 'Jake']

Get all rows without filter:

employees.get_all()  # you could also use the 'only_column' parameter here
[{"id": "1", "firstname": "Chuck", "lastname": "Norris"}, {"id": "42", "firstname": "John", "lastname": "Johnson"}, {"id": "1337", "firstname": "Linus", "lastname": "Bartsch"}, {"id": "9001", "firstname": "Jake", "lastname": "Johnson"}]

Update

employees.update('id', 1337, {'lastname': 'Torvalds'})

Delete

employees.delete('id', 1337)

Create new table

create_table("customers",
            Column("firstname", TEXT, not_null=True),
            Column("lastname", TEXT, not_null=True),
            Column("email", TEXT, not_null=True, unique=True),
            Column("prime_member", INTEGER, default=0),
            Column("delivery_address", TEXT)
            )

About

Wrapper for sqlite3, to easily handle your data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages