Skip to main content

Better than sqlite3

Project description

SQLLEX alpha v0.1.5 📚

Python:3.9 Language grade: Python Total alerts


Better than sqlite3. Seriously, try it out

Installation

pip install sqllex

About

Use databases without thinking about SQL. Let me show you how sqllex makes your life easier. Imagine you need create some database, save some data into it and take it back. That's how your code will look like.

from sqllex import *

# Create some database, with simple structure
db = SQLite3x(
    path='my_data.db',
    template= {
        "users": {
            "username": [TEXT, NOT_NULL],
            "age": INTEGER,
        }
    }
)

# Insert some data
db.insert('users', ['Sqllex', 33])

# Take it back
users = db.select('username', from_table='users', where={'age': 33})

print(users)  # [('Squllex',)]

Ok, what if you need more complex structure with FOREIGN KEYs? Not a big deal.

from sqllex import *

DB_TEMPLATE = {
    "groups": {
        "group_id": [INTEGER, PRIMARY_KEY, UNIQUE],
        "name": [TEXT, NOT_NULL, DEFAULT, 'Unknown'],
    },

    "users": {
        "username": [TEXT, NOT_NULL],
        "group_id": INTEGER,

        FOREIGN_KEY: {
            "group_id": ["groups", "group_id"]
        },
    }
}

# and do your business ...

What if I have LARGE dataset to insert? Still easy.

...
# Your awesome dataset
dataset = [
    [3, "pi", 0],
    [1, "pi", 1],
    [4, "pi", 2],
    [1, "pi", 3],
    [5, "pi", 4],
    [9, "pi", 5],
    [2, "pi", 6],
    ...
]

# One line
db.insertmany('math', dataset)

# Done

Advances

Ok ok, what if you are SUPER_PRO_1337_SQL_GOY, and you need 100% of SQL features. Check this out.

from sqllex import *

db = SQLite3x(
    path='./path/my_awesome.db',
    template={
        "groups": {
            "group_id": [INTEGER, PRIMARY_KEY, UNIQUE],
            "name": [TEXT, NOT_NULL, DEFAULT, 'Unknown'],
        }
    }
)

# Insert some groups into groups table
db.insertmany(
    'groups',
    group_id=[1, 2],
    name=["Admin", "User"],
)


# Let's create a new table with some FOREIGN_KEYs
db.create_table(
    name='users',
    columns={
        "username": [TEXT, NOT_NULL, DEFAULT, 'Unknown'],
        "group_id": INTEGER,
        FOREIGN_KEY: {
            "group_id": ["groups", "group_id"]
        },
    },
    without_rowid=True,
    as_=__something__
)

# Insert some users into users table
db.insertmany(
    table='users',
    username=['User_1', 'User_2', 'User_3', 'User_4', 'User_5', 'User_6'],
    group_id=[1, 2, 1, 1, 2, 2]
)

db.insert(
    or_=REPLACE,
    table='users',
    username='User_4',
    group_id=1,
)

# ANd now take it back whith some conditions
users = db.select(
    select='username',
    table='users',
    where={
        'group_id': 2
    },
    order_by={
        'username': 'DESC'
    },
    with_=__something__,
    limit=10,
    offset=1,
    execute=True,
)

# and do your business ...

Not enough? Need examples? Read more in Sqllex Wiki! (link)


Other

TODO-list

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

sqllex-0.1.5.1.tar.gz (13.2 kB view details)

Uploaded Source

File details

Details for the file sqllex-0.1.5.1.tar.gz.

File metadata

  • Download URL: sqllex-0.1.5.1.tar.gz
  • Upload date:
  • Size: 13.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.9.2

File hashes

Hashes for sqllex-0.1.5.1.tar.gz
Algorithm Hash digest
SHA256 d717df13e179e1976d73b7b7ae4b3ef05d85db4f028c2db93387c49c17b0a5f1
MD5 28ba69f8e9c4733320f2477731629cc8
BLAKE2b-256 4ea89609d81b3c12e75a34a562c92111e64cdf341b81834be6e896b80bb43728

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