mirror of
https://github.com/hanzoai/datastore-orm.git
synced 2026-09-30 21:40:30 +00:00
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.
43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
|
|
import unittest
|
|
import json
|
|
|
|
from datastore_orm import database, engines, fields, models
|
|
|
|
|
|
class JoinTest(unittest.TestCase):
|
|
|
|
def setUp(self):
|
|
self.database = database.Database('test-db', log_statements=True)
|
|
self.database.create_table(Foo)
|
|
self.database.create_table(Bar)
|
|
self.database.insert([Foo(id=i) for i in range(3)])
|
|
self.database.insert([Bar(id=i, b=i * i) for i in range(3)])
|
|
|
|
def print_res(self, query):
|
|
print(query)
|
|
print(json.dumps([row.to_dict() for row in self.database.select(query)]))
|
|
|
|
def test_without_db_name(self):
|
|
self.print_res("SELECT * FROM {}".format(Foo.table_name()))
|
|
self.print_res("SELECT * FROM {}".format(Bar.table_name()))
|
|
self.print_res("SELECT b FROM {} ALL LEFT JOIN {} USING id".format(Foo.table_name(), Bar.table_name()))
|
|
|
|
def test_with_db_name(self):
|
|
self.print_res("SELECT * FROM $db.{}".format(Foo.table_name()))
|
|
self.print_res("SELECT * FROM $db.{}".format(Bar.table_name()))
|
|
self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN $db.{} USING id".format(Foo.table_name(), Bar.table_name()))
|
|
|
|
def test_with_subquery(self):
|
|
self.print_res("SELECT b FROM {} ALL LEFT JOIN (SELECT * from {}) subquery USING id".format(Foo.table_name(), Bar.table_name()))
|
|
self.print_res("SELECT b FROM $db.{} ALL LEFT JOIN (SELECT * from $db.{}) subquery USING id".format(Foo.table_name(), Bar.table_name()))
|
|
|
|
|
|
class Foo(models.Model):
|
|
id = fields.UInt8Field()
|
|
engine = engines.Memory()
|
|
|
|
|
|
class Bar(Foo):
|
|
b = fields.UInt8Field()
|