Skip to main content

A simple and extensible SQL migration and loader utility for Python.

Project description

sqloader

A lightweight Python utility for managing SQL migrations and loading SQL from JSON or .sql files. Supports common relational databases and is designed for simple, clean integration with any Python backend (e.g., FastAPI).


Installation

pip install sqloader

Features

  • ✅ Easy database migration management
  • ✅ Load SQL queries from .json or .sql files
  • ✅ Supports MySQL and SQLite
  • ✅ Clean API for integration
  • ✅ Lightweight and dependency-minimized

Quickstart

from sqloader.init import database_init

config = {
    "type": "mysql",
    "mysql": {
        "host": "localhost",
        "port": 3306,
        "user": "root",
        "password": "pass",
        "database": "mydb"
    },
    "service": {
        "sqloder": "res/sql/sqloader/mysql"
    },
    "migration": {
        "auto_migration": True,
        "migration_path": "res/sql/migration/mysql"
    },
}

db, sqloader, migrator = database_init(config)

# Example usage
query = sqloader.load_sql("user_info", "user.get_user_by_id")
result = db.fetch_one(query, ['abc', 123])

SQL Loading Behavior

  • If the value in the .json file ends with .sql, the referenced file will be loaded from the same directory.
  • Otherwise, the value is treated as a raw SQL string.

Example JSON file user.json:

{
  "user": {
    "get_user_by_id": "SELECT * FROM users WHERE id = %s",
    "get_all_users": "user_all.sql"
  },
  "get_etc": "SELECT * FROM etc"
}

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

sqloader-0.1.2.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

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

sqloader-0.1.2-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file sqloader-0.1.2.tar.gz.

File metadata

  • Download URL: sqloader-0.1.2.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for sqloader-0.1.2.tar.gz
Algorithm Hash digest
SHA256 1b3296f38ce751627c09c67eb74d398823620908faf63688ffdf0ab13901d799
MD5 1448c2ecb8b01ee75385c5fd5e8abacd
BLAKE2b-256 6e9447b3e6ceee94c1534891a0268e1d426d5fd7aaf6c2c3793b1858aa15fbb4

See more details on using hashes here.

File details

Details for the file sqloader-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sqloader-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for sqloader-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f92e343354b3fc1f11715ee317a8a3e806909d112806c7e6398a214cfb8ebac1
MD5 ff07f9b4cc676bb2036b584f1fec5760
BLAKE2b-256 ca8b67c7eba1664327f50254988391e2b3617a527a80f5ab8366ecf5d511ed34

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