Files
infi.clickhouse_orm/docs/importing_orm_classes.md
zeekay dda3979851 rename: the ORM is ours — datastore_orm, not infi.clickhouse_orm
This is our fork, so it should read like it. `import datastore_orm` instead of
`from infi.clickhouse_orm import ...`: `infi` was the original vendor's org
namespace, and carrying someone else's org name through every import in the
consuming codebase is not a fork, it is a vendored copy that never got renamed.

The `infi` namespace package is gone entirely (src/infi/__init__.py with it),
the distribution is `datastore-orm`, and the metadata points at Hanzo rather
than at the upstream repo and author.

NOT renamed, deliberately: the migration history tables are still
`infi_clickhouse_orm_migrations`. That name is persisted state — 448 rows in
production key off it — so changing it is a data migration, not a rename. Doing
it carelessly reproduces the exact failure this fork just hit, where a package
rename orphaned the history and silently blocked every migration.
2026-07-26 08:44:11 -07:00

2.6 KiB

Importing ORM Classes

The ORM supports different styles of importing and referring to its classes, so choose what works for you from the options below.

Importing Everything

It is safe to use import * from datastore_orm or its submodules. Only classes that are needed by users of the ORM will get imported, and nothing else:

from datastore_orm import *

This is exactly equivalent to the following import statements:

from datastore_orm.database import *
from datastore_orm.engines import *
from datastore_orm.fields import *
from datastore_orm.funcs import *
from datastore_orm.migrations import *
from datastore_orm.models import *
from datastore_orm.query import *
from datastore_orm.system_models import *

By importing everything, all of the ORM's public classes can be used directly. For example:

from datastore_orm import *

class Event(Model):

    name = StringField(default="EVENT")
    repeated = UInt32Field(default=1)
    created = DateTimeField(default=F.now())

    engine = Memory()

Importing Everything into a Namespace

To prevent potential name clashes and to make the code more readable, you can import the ORM's classes into a namespace of your choosing, e.g. orm. For brevity, it is recommended to import the F class explicitly:

import datastore_orm as orm
from datastore_orm import F

class Event(orm.Model):

    name = orm.StringField(default="EVENT")
    repeated = orm.UInt32Field(default=1)
    created = orm.DateTimeField(default=F.now())

    engine = orm.Memory()

Importing Specific Submodules

It is possible to import only the submodules you need, and use their names to qualify the ORM's class names. This option is more verbose, but makes it clear where each class comes from. For example:

from datastore_orm import models, fields, engines, F

class Event(models.Model):

    name = fields.StringField(default="EVENT")
    repeated = fields.UInt32Field(default=1)
    created = fields.DateTimeField(default=F.now())

    engine = engines.Memory()

Importing Specific Classes

If you prefer, you can import only the specific ORM classes that you need directly from datastore_orm:

from datastore_orm import Model, StringField, UInt32Field, DateTimeField, F, Memory

class Event(Model):

    name = StringField(default="EVENT")
    repeated = UInt32Field(default=1)
    created = DateTimeField(default=F.now())

    engine = Memory()

<< Expressions | Table of Contents | Querysets >>