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.3.tar.gz (10.6 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.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sqloader-0.1.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sqloader-0.1.3.tar.gz
Algorithm Hash digest
SHA256 54823b679b47bb0271c985d94694f44749133b37dfce42e5e4ccf33ed624c632
MD5 f8a6cc7a75c82ff583082e391c3169b7
BLAKE2b-256 aab5644934bb16f2cbe6a4854398deadaad46cf7032bc76b10b6385f92e78e28

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sqloader-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for sqloader-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 ac7c4a22e556a9fcf292f54974064b214fbb8261353295d6d76056bfe0c1c198
MD5 2112fb07a82fd396c0998eb63dae3a03
BLAKE2b-256 0c0bca1ae96bee184fa5d0f76cf9f07b027551e90964879315f215311689d015

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