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.1-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: vetariasn-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8e822f8734f2d919f5303d9351de1faa17fbafe1c51932faa2ccf7c081109bd6
MD5 404c5777040111c1be6b17327c4acc42
BLAKE2b-256 ec6278a1b76eec5059860162de6a2c020e597d4b228911200c6c3050d9734e56

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