Skip to main content

A simple library that covers sqlite3's basic functionality.

Project description

ExenDB

A simple library that covers sqlite3's basic functionality.

Copyright 2022-present Exenifix. Licensed under MIT License, see LICENSE for details.

Installation

Using pip

$ python -m pip install -U exendb
# or
$ pip install -U exendb

From source

$ pip install -U git+https://github.com/Exenifix/ExenDB

Quickstart

Creating a table

from exendb import Database, SQLType

db = Database('test')
table = db.create_table(
    'users', 
    id=SQLType.UNIQUE(SQLType.INT), #column named id with type INT with unique value
    name=SQLType.TEXT, #named name, type TEXT
    surname=SQLType.TEXT, #named surname, type TEXT
    is_male=SQLType.BOOL) #named is_male, type BOOL

Adding values to table

...
table.insert_row(151, 'John', 'Wisley', True)
table.insert_row(157, 'Joe', 'Astley', True)
table.insert_row(651, 'Mary', 'Bart', False)
...

Getting dict-like values

...
all_rows = table.get_all_rows() #type: list[dict]
single_row = table.get_single_row('id = 151') #type: dict
...

Updating existing row

...
table.update('id = 651', name='Marie')
...

Deleting row

...
table.delete_row('name = "John" AND surname = "Wisley"')
...

More examples in sample_table.py

Classes

Database

Class representing a database.

Attributes

  • name: str

    Name of the database (without file extension).

  • file_name: str

    Filename of the database we connect to.

  • tables: property, str

    List of tables that belong to this database.

Methods

  • get_table(name: str) -> Table

    Returns Table object if found in database's tables list.

  • create_table(name: str, **columns: SQLType) -> Table

    Creates a new table and returns Table object.

  • delete_table(name: str)

    Removes an existing table from the database.

  • select(*args, **kwargs) -> Union[dict, list]

    Performs a SELECT query to the database.


Table

Class representing a database table. You don't construct this by yourself.

Attributes

  • db: Database

    The database this table belongs to.

  • name: str

    Name of the table.

  • columns: property, list[str]

    List of column names.

Methods

  • rename(new_name: str)

    Renames the table to a new name.

  • delete()

    Deletes the table from the database.

  • add_column(name: str, _type: SQLType)

    Creates a new column with the given name and type.

  • remove_column(name: str)

    Removes a column with the given name.

  • rename_column(name: str, new_name: str)

    Renames a column with the given name to a new name.

  • get_single_row(*columns, where: str)

    Returns a SINGLE row of data in dict format, where keys are column names and values are rows values.

  • get_multiple_rows(*columns, **kwargs)

    Returns all the rows matching the given conditions.

  • get_all_rows(*columns, **kwargs)

    Returns all the rows. Equivalent to to get_multiple_rows without where kwarg.

  • insert_row(*data)

    Inserts a row into the database for the given column names.

  • update(_where: str = None, **data)

    Sets the values of the row(s) meeting the condition to the new data.

  • delete_row(where: str):

    Deletes all the rows in the table meeting the condition.

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

exendb-0.0.2.tar.gz (8.5 kB view details)

Uploaded Source

Built Distribution

exendb-0.0.2-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file exendb-0.0.2.tar.gz.

File metadata

  • Download URL: exendb-0.0.2.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for exendb-0.0.2.tar.gz
Algorithm Hash digest
SHA256 caf2d638ad39ce7facbbbf0f4d1973496e5dc16c59158e144d39d309e7969765
MD5 b39d6659a45f3db97fd3872ab46f497d
BLAKE2b-256 7592c03e49ca30ed384f6edd564b221285e536644fff700881ddd6bbc83ad831

See more details on using hashes here.

File details

Details for the file exendb-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: exendb-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.10

File hashes

Hashes for exendb-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 7f8bb9114c1ad1ac450d1839da3e1860aa0d28dd964bae6f39b006d1f75cf592
MD5 d19e3c34fb5c26e0ba9150cbefbf7063
BLAKE2b-256 f21a3b8d3e5075950a21c2a6f3579de569d8cf2df6de1985581dbc293cb957bd

See more details on using hashes here.

Supported by

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