|
| 1 | +======================= |
| 2 | +DBDuck Initialization Guide |
| 3 | +======================= |
| 4 | + |
| 5 | +This guide is for the current production-focused stage of DBDuck with SQL and NoSQL support. |
| 6 | + |
| 7 | +Environment |
| 8 | +=========== |
| 9 | + |
| 10 | +.. code-block:: bash |
| 11 | +
|
| 12 | + python -m venv .venv |
| 13 | + .venv\\Scripts\\activate |
| 14 | + pip install -r requirements.txt |
| 15 | +
|
| 16 | +Local Source Priority |
| 17 | +===================== |
| 18 | + |
| 19 | +When running from ``examples/``, keep local source first: |
| 20 | + |
| 21 | +.. code-block:: python |
| 22 | +
|
| 23 | + import sys |
| 24 | + from pathlib import Path |
| 25 | + sys.path.insert(0, str(Path(__file__).resolve().parents[1])) |
| 26 | +
|
| 27 | +SQL Initialization |
| 28 | +================== |
| 29 | + |
| 30 | +SQLite |
| 31 | +------ |
| 32 | + |
| 33 | +.. code-block:: python |
| 34 | +
|
| 35 | + from DBDuck import UDOM |
| 36 | + |
| 37 | + db = UDOM(db_type="sql", db_instance="sqlite", url="sqlite:///test.db") |
| 38 | + print(db.create("Product", {"name": "Keyboard", "price": 99, "active": True})) |
| 39 | + print(db.find("Product", where={"active": True})) |
| 40 | +
|
| 41 | +MySQL |
| 42 | +----- |
| 43 | + |
| 44 | +.. code-block:: python |
| 45 | +
|
| 46 | + db = UDOM(db_type="sql", db_instance="mysql", url="mysql+pymysql://root:password@localhost:3306/udom") |
| 47 | +
|
| 48 | +PostgreSQL |
| 49 | +---------- |
| 50 | + |
| 51 | +.. code-block:: python |
| 52 | +
|
| 53 | + db = UDOM(db_type="sql", db_instance="postgres", url="postgresql+psycopg2://postgres:password@localhost:5432/postgres") |
| 54 | +
|
| 55 | +Supported SQL Engines |
| 56 | +--------------------- |
| 57 | + |
| 58 | +- ``sqlite`` |
| 59 | +- ``mysql`` |
| 60 | +- ``postgres`` |
| 61 | +- ``mssql`` |
| 62 | + |
| 63 | +NoSQL Initialization (MongoDB) |
| 64 | +============================== |
| 65 | + |
| 66 | +.. code-block:: python |
| 67 | +
|
| 68 | + db = UDOM(db_type="nosql", db_instance="mongodb", url="mongodb://localhost:27017/udom") |
| 69 | + print(db.execute("ping")) |
| 70 | + print(db.create("events", {"type": "login", "ok": True})) |
| 71 | + print(db.find("events", where={"ok": True})) |
| 72 | +
|
| 73 | +Mongo Transactions |
| 74 | +------------------ |
| 75 | + |
| 76 | +.. code-block:: python |
| 77 | +
|
| 78 | + with db.transaction(): |
| 79 | + db.create("events", {"type": "purchase", "ok": True, "amount": 120.50}) |
| 80 | +
|
| 81 | +Mongo Index Management |
| 82 | +---------------------- |
| 83 | + |
| 84 | +.. code-block:: python |
| 85 | +
|
| 86 | + db.ensure_indexes( |
| 87 | + "events", |
| 88 | + [ |
| 89 | + {"fields": [{"name": "type", "order": "asc"}], "options": {"name": "idx_type"}}, |
| 90 | + ], |
| 91 | + ) |
| 92 | +
|
| 93 | +Validation Commands |
| 94 | +=================== |
| 95 | + |
| 96 | +.. code-block:: bash |
| 97 | +
|
| 98 | + python -m py_compile DBDuck/udom/udom.py |
| 99 | + python examples/app_production.py |
| 100 | + python examples/example_sqlite.py |
| 101 | + python examples/example_mongo.py |
| 102 | + python -m examples.dbs.sqlite.basic |
| 103 | + python -m examples.dbs.sqlite.advanced |
| 104 | +
|
| 105 | +Current Scope |
| 106 | +============= |
| 107 | + |
| 108 | +- Production focus: SQL + MongoDB |
| 109 | +- In progress: Graph + AI + Vector |
| 110 | + |
| 111 | +CI Test Pipeline |
| 112 | +================ |
| 113 | + |
| 114 | +GitHub Actions workflow: ``.github/workflows/ci.yml`` |
| 115 | + |
| 116 | +Local equivalent: |
| 117 | + |
| 118 | +.. code-block:: bash |
| 119 | +
|
| 120 | + pytest -q |
| 121 | +
|
| 122 | +Security checks: |
| 123 | + |
| 124 | +.. code-block:: bash |
| 125 | +
|
| 126 | + pip-audit --desc |
| 127 | + bandit -q -r DBDuck |
| 128 | +
|
| 129 | +Runtime Config |
| 130 | +============== |
| 131 | + |
| 132 | +Use ``.env.example`` as baseline for production environment variables. |
| 133 | + |
| 134 | +SQL Migrations |
| 135 | +============== |
| 136 | + |
| 137 | +Use Alembic baseline in ``migrations/sql/``: |
| 138 | + |
| 139 | +.. code-block:: bash |
| 140 | +
|
| 141 | + $env:DATABASE_URL="sqlite:///test.db" |
| 142 | + dbduck makemigrations --module myapp.models --message "init" |
| 143 | + dbduck migrate --direction up |
| 144 | +
|
| 145 | +Mongo Integration Tests |
| 146 | +======================= |
| 147 | + |
| 148 | +.. code-block:: bash |
| 149 | +
|
| 150 | + $env:RUN_MONGO_INTEGRATION="1" |
| 151 | + $env:MONGO_TEST_URL="mongodb://localhost:27017/udom_test" |
| 152 | + pytest -q tests/integration |
| 153 | +
|
| 154 | +Logo Asset |
| 155 | +========== |
| 156 | + |
| 157 | +Expected logo location: |
| 158 | + |
| 159 | +- ``docs/assets/dbduck-logo.png`` |
0 commit comments