Skip to main content

Vetariasn: An new framework for developing great application

Project description

Vetariasn: An new framework for developing great application

Usage

This is API example.

# An simple CRUD example.
import vetariasn as vt

class Employee(vt.orm.Base):
    # vt.orm.Base is an subclass of sqlalchemy.orm.DeclarativeBase
    # __tablename__ is optional. Convention over Configuration.
    uid = vt.orm.op.Column(int, primary_key=True) # vt.orm.op == sqlalchemy
    name = vt.orm.op.Column(str, unique=True, nullable=False)

class Message(vt.transient.Base):
    # vt.transient: in-memory sqlite ORM API.
    seq = vt.orm.op.Column(int, primary_key=True)
    sender = vt.orm.op.Column(int, primary_key=True)
    target = vt.orm.op.Column(int, primary_key=True)
    content = vt.orm.op.Column(vt.orm.op.Text(), nullable=False)

# Create.
@vt.http.get("/create-employee")
async def create_employee(name: str):
    async with vt.orm.Session() as session:
        uid = vt.algo.calc_seqid() # Snowflake UID
        # An simple creation operation
        result = (await session.execute(
            vt.orm.op.select(Employee)
            .where(Employee.name == name)
        )).fetchone()
        if result is not None:
            return {"uid": result._tuple()[0].uid, "already": True}
        session.add(Employee(uid=uid, name=name))
        await session.commit()
    return {"uid": uid, "already": False}

# Read.
@vt.http.get("/get-employee/{name}")
async def get_employee_by_name(name: str):
    async with vt.orm.Session() as session:
        result = (await session.execute(
            vt.orm.op.select(Employee)
            .where(Employee.name == name)
        )).fetchone()
        if result is None:
            return {"found": False, "uid": 0, "name": ""}
        employee = result._tuple()[0]
        return {"found": True, "uid": employee.uid, "name": employee.name}

# Start system.
if __name__ == "__main__":
    vt.run()

Environment Variables

Variable Description
VETA_DB_URL Database URL (Sqlalchemy Async)
VETA_HTTP_PORT HTTP Web Port

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

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

vetariasn-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file vetariasn-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vetariasn-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.3

File hashes

Hashes for vetariasn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1bca4bfec8cb25e63b20590a34564934bf51d2cab764042fdf1ee1dd3fb695ef
MD5 9f765fe3f2ee333ffeefbff4daa255d8
BLAKE2b-256 ddbbdcd992df2c9da0f9b9b1a5913bd3ec56b3d28ddf91392ca121c6a94357c2

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