Skip to main content

basesqlmodel

Latest Commit
Package version

A very simple CRUD class for SQLModel! :sparkles:

Installation

pip install basesqlmodel

Usage

import asyncio

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine
from sqlalchemy.orm import sessionmaker
from sqlmodel import Field

from basesqlmodel import Base

engine = create_async_engine("sqlite+aiosqlite:///:memory:")
SessionLocal = sessionmaker(engine, expire_on_commit=False, class_=AsyncSession)


class Potato(Base, table=True):
    id: int = Field(primary_key=True)
    name: str


async def main():
    # Create tables
    async with engine.begin() as conn:
        await conn.run_sync(Base.metadata.create_all)

    # Interact with the Potato table
    async with SessionLocal() as session:
        obj = await Potato.create(session, name="Potato")
        print(f"Potato created: {repr(obj)}")

        obj = await Potato.get(session, name="Potato")
        print(f"Potato retrieved: {repr(obj)}")

        await obj.update(session, name="Fake Potato")
        print(f"Potato updated: {repr(obj)}")

        await Potato.delete(session, name="Fake Potato")
        print(f"Potato deleted: {repr(obj)}")

        objs = await Potato.get_multi(session)
        print(f"Confirm that the database is empty: {objs}")


asyncio.run(main())

License

This project is licensed under the terms of the MIT license.

Metadata

Release files for basesqlmodel 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for basesqlmodel 0.1.0
File Size Uploaded
basesqlmodel-0.1.0.tar.gz 4.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for basesqlmodel 0.1.0
File Interpreter ABI Platform
basesqlmodel-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / basesqlmodel-0.1.0.tar.gz

Download URL basesqlmodel-0.1.0.tar.gz
Size 4.1 kB
Tags Source
SHA-256 checksum
How to use checksums
b9ae90978d0f78019007f3ba4de890c5abe3a4defc5720ab4066606ae74fdb4b
BLAKE2b-256 checksum
How to use checksums
db75538c05ed7564b3e63749738491e7330373f5dc48990903a6adafcae1484c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.9.7 Linux/5.11.0-34-generic

Release files / basesqlmodel-0.1.0-py3-none-any.whl

Download URL basesqlmodel-0.1.0-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c85b9a66d769b1e8e4fe96eed93f0d81e985643cdcf955eaf25aee5fa5380ee3
BLAKE2b-256 checksum
How to use checksums
9cf99c46c7f60f77ee5f8ecb14f8d60e75fef9fd16272248db33dee637149869
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.9.7 Linux/5.11.0-34-generic

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page