Skip to main content

Python3 tool to create and handle very quickly a sqlite3 database in an application

Project description

logo silly db

Silly DB

It is ...

Not an ORM, even though it may "look and feel like" one in some aspects.

  • Build the structure of your DB from classic .sql files.
  • Queries return directly usefull python objects like an ORM would do.

Some SQL knowledge is required, the purpose of Silly DB is not to get rid of SQL (actualy, SQL is the best tool to manage... a SQL database), but to handle the boring things, and let you focus on your application.

The required knowledge and much more is available here :

You should consider using 'DB Browser for SQLite':

No need to be an expert, just understand own to create a DB and use 'SELECT' will be fine (see the examples files to get quickly some bases).

Installation

$ pip install silly_db

Fast way to begin

Create a new directory and open a console in there.

Get a basic working structure with 'plop':

$ python3 -m silly_db.plop db

Congratulations ! You've got your database ready to work ! To understand how it works, open the differents files provided and read the comments, it will be easy to adapt to your own needs.

get more info with:

$ python3 -m silly_db

and more about the plop options here:

$ python3 _n silly_db.plop

Silly DB gives a hand with:

  • DB object (methods: execute, migrate, export, export_structure, select)

  • Selection / SelectionItem

  • Selection.exists() -> bool

  • Selection.jsonify() -> list of dict

  • Selection.__add__() (new = selection1 + selection2 #without duplications)

  • Selection.order_by(key='a_column_name', reverse=False)

  • SelectionItem are convertible to dict: dico = dict(SelectionItem)

  • Migrations made easy

  • Quick start with plop

And some more... fix the sql 'quotes' problem with silly_db.helpers.to_sql:

name = to_sql("tim's") # convert ' into '' (escaped quote)
db.execute(f"INSERT INTO 'guys' ('name') VALUES('{name}')")

About queries

Queries are done just as it is in SQL, but with the DB.select() method. A query returns a Selection object (list of SelectionItem objects). Attributes are automaticaly gathered from the query.

A Selection object can be converted into a json format.

>>> some_json = selection.jsonify()

A SelectionItem object can be converted into a dict:

>>> dico = dict(selection_item)

Short example:

>>> selection = db.select(
    "cat.name as cat, person.name as owner FROM cat JOIN person ON "
    "cat.owner_id=person.id WHERE cat.owner_id=1"
    )
>>> print(selection)
<Selection[{cat: Chat, owner: Irina, }, {cat: snow_ball, owner: Irina, }, ]>
>>> selection.items[1].cat
'snow_ball'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

silly-db-1.0.7.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

silly_db-1.0.7-py3-none-any.whl (10.9 kB view details)

Uploaded Python 3

File details

Details for the file silly-db-1.0.7.tar.gz.

File metadata

  • Download URL: silly-db-1.0.7.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for silly-db-1.0.7.tar.gz
Algorithm Hash digest
SHA256 313d28d72c169ee0b514293a533be578daed768e1174d35cbe234e23589069f4
MD5 1c986dccf4b4692a7bfcbfae87c5d4de
BLAKE2b-256 e6bbb702ccd5400b24ffe11308eb6976fc445fee73523822ee98781ea6b57bd7

See more details on using hashes here.

File details

Details for the file silly_db-1.0.7-py3-none-any.whl.

File metadata

  • Download URL: silly_db-1.0.7-py3-none-any.whl
  • Upload date:
  • Size: 10.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.26.0 requests-toolbelt/0.9.1 urllib3/1.26.6 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.6

File hashes

Hashes for silly_db-1.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 355e399f7cbd0f002dc9ce24da9148a1556c21677bf5a44d40756744d73dcc2e
MD5 733228ca9b00084b49e418f0f79d6e66
BLAKE2b-256 cd0c646fef0d70051c51d31e3df540d465fd28f4aa99a04a2fe0750686a2feaf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page