Usage

Note: This usage is copied from the project’s Features.md

Table of contents

  1. More filter

    1. Some Constraints

  2. Table-related operation

    1. Select

    2. Update

    3. Delete

    4. Insert

    5. Functions

  3. Database-related operation

    1. Create Table

    2. Delete Table

    3. Accessing Table

    4. Reset Table

    5. Rename Table

    6. Check Table

    7. All Tables

  4. Export

    1. Export Table

    2. Export Database

Note: to test these features, make sure you copy and paste this snippet:

from sqlite_database import op
from sqlite_database.operators import eq, like, between
value = 0 # You can use almost anything.

For table and database, you can create any dummy database but here’s one (assuming you have pasted the above snippet):

from sqlite_database import Database, integer, text
db = Database(":memory:")
table = db.create_table('table', [
    integer('row'),
    text('row2')
])

More filter

Basic

data = table.select({
    "row": op == value
})

Basic (new equal) (v0.1.2)

data = table.select({
    'row': value
})

List (v0.1.2)

data = table.select([
    eq('row', value)
])

Any other variations are just math operators, for the list, operations can be obtained from the operators module.

Some constraints

Like constraint

data = table.select([
    like('row2', 'te%t')
])

Between constraint

data = table.select([
    between('row', 0, 10)
])

Export

You can export the database/table to CSV, for now, import functionality will not be added.

Make sure to add this line

from sqlite_database.csv import to_csv_file, to_csv_string

You can use to_csv_string rather than to_csv_file, all you need is to pass the table or database.

Note: The return type for the database is a tuple indicating (name, csv), and by that, to_csv_file would make sure that filename passed is a directory and the content will be all table files. E.g: /path/database/table.csv

Export Table

# To String
csv = to_csv_string(db.table("table"))

# To file
to_csv_file(db.table("table"), "table.csv")

Export Database

# To String
csv = to_csv_string(db) # list[(name, csv)]

# To directory
to_csv_file(db.table("table"), "DatabasePath")