Skip to main content

SQLow is a lightweight Python library designed to streamline SQLite database operations with a focus on file-like data management.

Project description

SQLow: DataClass SQLite Database Management for File-like Operations

SQLow is a lightweight Python library that simplifies SQLite database operations, specifically tailored for file-like data management. For example, if you work with frontend components written in TypeScript or JavaScript, SQLow offers an intuitive way to manage data as if they were files, all while benefiting from the power and efficiency of an SQLite database.

Key Features

  • Simplified Database Operations: SQLow streamlines database interactions using data classes and decorators, abstracting away the complexity of SQL queries.
  • Efficient Data Serialization: It efficiently handles data serialization for various data types, ensuring seamless integration with your codebase.
  • Automatic Table Management: SQLow automatically creates and manages database tables, sparing you from manual table setup.
  • Customizable Table Configuration: Tables can be configured with decorators, allowing you to define unique constraints and relationships.

Installation

You can install SQLow using the following command:

pip install sqlow

Methods

Method Description
set(**kwargs) Inserts or Updates a row in the database. If a row with the given name exists, it updates the row.
get(id: int) Retrieves a single row from the database by its id.
get_by(**kwargs) Retrieves a single row from the database by its key and value.
all() Retrieves all rows from the database and returns them as a list of dictionaries.
delete(**kwargs) Deletes a single row from the database by its key and value.
delete_all() Deletes all rows from the database.
drop() Drops the entire table from the database.
dump(file_path) Save table to a JSON file.
load(file_path) Load table from a JSON file.

Note

In SQLow, all tables include id and name columns. This design choice aligns with the file-like nature of the data and simplifies operations.

Usage Example

Here's a practical example that demonstrates how to use SQLow to manage file-like data in an SQLite database.

import datetime

from sqlow import sqlow

# Initialize SQLow with the SQLite database
sqlite = sqlow("db.sqlite3")

# Define a table using the SQLow decorator
@sqlite
class Components:
    project_id: int
    docs: str
    meta: dict
    info: list
    date: datetime.datetime

# Create an instance of the table
table = Components()

# Insert data into the table
table.set(
    name="button",
    project_id=1,
    docs="Component documentation",
    meta={"author": "John Doe"},
    info=[1, 2, 3]
    date=datetime.datetime.now(datetime.UTC),
)

# Retrieve a single record by name
item = table.get_by(name="button")
print("Retrieved Item:", item)

# Retrieve all records from the table
all_items = table.all()
print("All Items:", all_items)

# Retrieve a single record by name
item_to_update = table.get_by(name="button")

# Update an existing record by name
item_to_update["meta"] = {"new-meta": "planeta"}
table.set(**item_to_update)

# Delete a record by name
table.delete(name="button")

# Delete all records from the table
table.delete_all()

# Drop the entire table
table.drop()

Usage of create_table

import datetime

from sqlow import create_table

fields = {
    "project_id": int,
    "docs": str,
    "meta": dict,
    "info": list,
    "date": datetime.datetime
}

table = create_table("db.sqlite3", "Components", **fields)

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

sqlow-0.1.6.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

sqlow-0.1.6-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file sqlow-0.1.6.tar.gz.

File metadata

  • Download URL: sqlow-0.1.6.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for sqlow-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e02697d07d2342d4b742ca66a7cbc116e94b36140445d4cdf0ed650bd2ec655e
MD5 b078fa50ce23687bd702d3ebd5e1f754
BLAKE2b-256 bb2a9cb472cd63df0f03ad55ebb2af1f3529c99298f5ca46c94492ace30c76c5

See more details on using hashes here.

File details

Details for the file sqlow-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: sqlow-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.19

File hashes

Hashes for sqlow-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 caf96ed1efe8a5cfe0f4cc4ce83fcb5309d94c270bee192699f999d3989f343a
MD5 7259ba6cc5e52ff341b675273e988bd3
BLAKE2b-256 b7aaf83c14c12f1eca821c6868a05492d100be133b7ac219dfeab83f6df03269

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