Skip to main content

Simple ORM for U2 Unidata databases

Project description

uofast-orm

Simple, fast ORM for U2 Unidata/UniVerse databases via uopy.

Install

pip install uofast-orm

Quick Start

import uopy
from uofast_orm import UopyModel

class Customer(UopyModel):
    _file_name = "CUSTOMERS"
    _field_names = ["NAME", "EMAIL", "PHONE", "ADDRESS"]
    _field_map = {
        "full_name": "NAME",
        "email_address": "EMAIL",
        "phone_number": "PHONE",
        "street_address": "ADDRESS",
    }

with uopy.connect(host="...", user="...", password="...", account="...") as session:
    # Create
    c = Customer(session)
    c.full_name = "Jane Smith"
    c.email_address = "jane@example.com"
    c.create("CUST001")

    # Read
    c = Customer(session, record_id="CUST001")
    print(c.full_name)

    # Update
    c.phone_number = "555-1234"
    c.update()

    # Query
    results = c.select('NAME = "Jane Smith"')

    # Delete
    c.delete()

Models

Subclass UopyModel and set class attributes:

Attribute Required Description
_file_name Yes U2 file name
_field_names Yes* List of DICT field names
_field_map No {"python_name": "DICT_NAME"} mapping
_enable_cache No Enable LRU cache (default: False)
_cache_max_size No Max cached records (default: 100)

* Can be omitted when _field_map is provided.

Named Fields with Alternative DICT

When multiple data files share a single DICT:

from uofast_orm import SmartFile, patch_uopy_file

# Option A: monkey-patch uopy.File globally (zero call-site changes)
patch_uopy_file()

# Option B: use SmartFile directly
with SmartFile("ORDERS") as f:
    rec = f.read_named_fields("ORD001", ["CUSTNO", "AMOUNT"],
                              dict_file="SHARED_DICT")
    f.write_named_fields("ORD001", {"AMOUNT": 999}, dict_file="SHARED_DICT")

Code Generator

Auto-generate model classes from U2 DICT definitions (requires Ollama):

uofast-generate CUSTOMERS \
  --host 192.168.1.10 --user admin --password secret \
  --account /u2/MYACCOUNT \
  --output customer_model.py

Falls back to template-based generation if Ollama is unavailable.

API Reference

UopyModel

Method Description
load() Load record from database
create(record_id) Create new record
update() Update existing record
delete() Delete record
save() Create or update (auto-detects)
get(field, default) Get field value (supports property or DB name)
set(field, value) Set field value (supports property or DB name)
to_dict(use_property_names) Export as dict
select(stmt, limit, offset) Run SELECT statement, return model list
read(record_id) Read single record, return model instance
read_many(ids, batch_size) Batch read, return model list
clear_cache() Clear LRU cache (classmethod)

Requirements

  • Python 3.8+
  • uopy (U2 Unidata/UniVerse client)
  • requests (for code generator Ollama calls)

License

MIT

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

uofast_orm-1.1.0.tar.gz (17.3 kB view details)

Uploaded Source

Built Distribution

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

uofast_orm-1.1.0-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file uofast_orm-1.1.0.tar.gz.

File metadata

  • Download URL: uofast_orm-1.1.0.tar.gz
  • Upload date:
  • Size: 17.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for uofast_orm-1.1.0.tar.gz
Algorithm Hash digest
SHA256 25949e92efc60bdf8392145d72321318b649a942593e83955fa24cc9d8fe73aa
MD5 c7a114f0d70454a0f7ec1054ea08a645
BLAKE2b-256 383c404cf0a74caba6b30b3e8927defba3b964af6ab23e29f5fb0ef76a45f430

See more details on using hashes here.

File details

Details for the file uofast_orm-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: uofast_orm-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for uofast_orm-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6c0596c731d2d9b523c18300503beeffa12ee36d4cafad6ae3ce0a7e180b27f
MD5 0c7cb384ea463f7dd5a019c12bf2c86b
BLAKE2b-256 bf927ccad37dda4f97669c40b22febf78941f891dc0eb161acdb766285b970ef

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