belgie-alchemy 0.1.0__py3-none-any.whl → 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,33 +1,7 @@
1
- """SQLAlchemy 2.0 building blocks for database models.
2
-
3
- This module provides opinionated defaults and utilities for SQLAlchemy:
4
- - Base: Declarative base with dataclass mapping and sensible defaults
5
- - Mixins: PrimaryKeyMixin (UUID), TimestampMixin (created/updated/deleted)
6
- - Types: DateTimeUTC (timezone-aware datetime storage)
7
-
8
- Usage:
9
- from belgie_alchemy import Base, PrimaryKeyMixin, TimestampMixin, DateTimeUTC
10
-
11
- class MyModel(Base, PrimaryKeyMixin, TimestampMixin):
12
- __tablename__ = "my_models"
13
-
14
- name: Mapped[str]
15
- created_on: Mapped[datetime] = mapped_column(DateTimeUTC)
16
-
17
- For complete auth model examples, see examples/alchemy/auth_models.py
18
- """
19
-
20
1
  from belgie_alchemy.adapter import AlchemyAdapter
21
- from belgie_alchemy.base import Base
22
- from belgie_alchemy.mixins import PrimaryKeyMixin, TimestampMixin
23
2
  from belgie_alchemy.settings import DatabaseSettings
24
- from belgie_alchemy.types import DateTimeUTC
25
3
 
26
4
  __all__ = [
27
5
  "AlchemyAdapter",
28
- "Base",
29
6
  "DatabaseSettings",
30
- "DateTimeUTC",
31
- "PrimaryKeyMixin",
32
- "TimestampMixin",
33
7
  ]
@@ -1,38 +1,43 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: belgie-alchemy
3
- Version: 0.1.0
3
+ Version: 0.2.0
4
4
  Summary: SQLAlchemy building blocks for Belgie
5
5
  Author: Matt LeMay
6
6
  Author-email: Matt LeMay <mplemay@users.noreply.github.com>
7
+ Requires-Dist: aiosqlite>=0.22.1
7
8
  Requires-Dist: belgie-proto
9
+ Requires-Dist: brussels>=0.2.0
8
10
  Requires-Dist: pydantic>=2.0
9
11
  Requires-Dist: pydantic-settings>=2.0
10
12
  Requires-Dist: sqlalchemy[asyncio]>=2.0
11
- Requires-Python: >=3.12
13
+ Requires-Python: >=3.12, <3.15
12
14
  Description-Content-Type: text/markdown
13
15
 
14
16
  # belgie-alchemy
15
17
 
16
- SQLAlchemy 2.0 building blocks for database models.
18
+ SQLAlchemy 2.0 utilities for Belgie.
17
19
 
18
20
  ## Overview
19
21
 
20
- `belgie-alchemy` provides opinionated defaults and utilities for SQLAlchemy:
22
+ `belgie-alchemy` provides the `AlchemyAdapter` and database settings for Belgie.
23
+ For SQLAlchemy building blocks (Base, mixins, types), use `brussels`:
21
24
 
22
25
  - **Base**: Declarative base with dataclass mapping and sensible defaults
23
26
  - **Mixins**: `PrimaryKeyMixin` (UUID), `TimestampMixin` (created/updated/deleted timestamps)
24
- - **Types**: `DateTimeUTC` (timezone-aware datetimes), `Scopes` (dialect-specific array/JSON storage)
27
+ - **Types**: `DateTimeUTC` (timezone-aware datetimes), `Json` (dialect-specific JSON storage)
25
28
 
26
- This module provides **building blocks only** - you define your own models.
29
+ The examples below use `brussels` directly so you can own your models.
27
30
 
28
31
  ## Quick Start
29
32
 
30
33
  ```python
31
34
  from datetime import datetime
32
- from belgie_alchemy import Base, PrimaryKeyMixin, TimestampMixin, DateTimeUTC
35
+ from brussels.base import DataclassBase
36
+ from brussels.mixins import PrimaryKeyMixin, TimestampMixin
37
+ from brussels.types import DateTimeUTC
33
38
  from sqlalchemy.orm import Mapped, mapped_column
34
39
 
35
- class Article(Base, PrimaryKeyMixin, TimestampMixin):
40
+ class Article(DataclassBase, PrimaryKeyMixin, TimestampMixin):
36
41
  __tablename__ = "articles"
37
42
 
38
43
  title: Mapped[str]
@@ -53,10 +58,10 @@ This gives you:
53
58
  Declarative base with dataclass mapping enabled:
54
59
 
55
60
  ```python
56
- from belgie_alchemy import Base
61
+ from brussels.base import DataclassBase
57
62
  from sqlalchemy.orm import Mapped, mapped_column
58
63
 
59
- class MyModel(Base):
64
+ class MyModel(DataclassBase):
60
65
  __tablename__ = "my_models"
61
66
 
62
67
  id: Mapped[int] = mapped_column(primary_key=True)
@@ -70,7 +75,7 @@ Features:
70
75
 
71
76
  - Consistent naming conventions for constraints
72
77
  - Automatic type annotation mapping (`datetime` → `DateTimeUTC`)
73
- - Dataclass mapping with `kw_only=True`, `repr=True`, `eq=True`
78
+ - Dataclass mapping for convenient instantiation
74
79
 
75
80
  ### Mixins
76
81
 
@@ -79,9 +84,10 @@ Features:
79
84
  Adds a UUID primary key with server-side generation:
80
85
 
81
86
  ```python
82
- from belgie_alchemy import Base, PrimaryKeyMixin
87
+ from brussels.base import DataclassBase
88
+ from brussels.mixins import PrimaryKeyMixin
83
89
 
84
- class MyModel(Base, PrimaryKeyMixin):
90
+ class MyModel(DataclassBase, PrimaryKeyMixin):
85
91
  __tablename__ = "my_models"
86
92
  # Automatically includes: id: Mapped[UUID]
87
93
  ```
@@ -98,9 +104,10 @@ The `id` field:
98
104
  Adds automatic timestamp tracking:
99
105
 
100
106
  ```python
101
- from belgie_alchemy import Base, TimestampMixin
107
+ from brussels.base import DataclassBase
108
+ from brussels.mixins import TimestampMixin
102
109
 
103
- class MyModel(Base, TimestampMixin):
110
+ class MyModel(DataclassBase, TimestampMixin):
104
111
  __tablename__ = "my_models"
105
112
  # Automatically includes:
106
113
  # - created_at: Mapped[datetime]
@@ -123,10 +130,11 @@ Timezone-aware datetime storage:
123
130
 
124
131
  ```python
125
132
  from datetime import datetime
126
- from belgie_alchemy import Base, DateTimeUTC
133
+ from brussels.base import DataclassBase
134
+ from brussels.types import DateTimeUTC
127
135
  from sqlalchemy.orm import Mapped, mapped_column
128
136
 
129
- class Event(Base):
137
+ class Event(DataclassBase):
130
138
  __tablename__ = "events"
131
139
 
132
140
  id: Mapped[int] = mapped_column(primary_key=True)
@@ -140,43 +148,43 @@ Features:
140
148
  - Always returns UTC-aware datetimes from database
141
149
  - Works with PostgreSQL, SQLite, MySQL
142
150
 
143
- #### Scopes
151
+ #### Json
144
152
 
145
- Dialect-specific array storage for permission scopes:
153
+ Dialect-specific JSON storage (JSONB on PostgreSQL):
146
154
 
147
155
  ```python
148
- from enum import StrEnum
149
- from belgie_alchemy import Base, Scopes
156
+ from brussels.base import DataclassBase
157
+ from brussels.types import Json
150
158
  from sqlalchemy.orm import Mapped, mapped_column
151
159
 
152
- class User(Base):
160
+ class User(DataclassBase):
153
161
  __tablename__ = "users"
154
162
 
155
163
  id: Mapped[int] = mapped_column(primary_key=True)
156
- # Option 1: Simple string array (works everywhere)
157
- scopes: Mapped[list[str] | None] = mapped_column(Scopes, default=None)
164
+ # Store scopes as JSON (works everywhere)
165
+ scopes: Mapped[list[str] | None] = mapped_column(Json, default=None)
158
166
  ```
159
167
 
160
168
  Features:
161
169
 
162
- - PostgreSQL: Uses native `ARRAY(String)` type
163
- - SQLite/MySQL: Uses JSON storage
164
- - Automatically converts StrEnum values to strings
165
- - Handles `None` values correctly
170
+ - PostgreSQL: Uses `JSONB`
171
+ - SQLite/MySQL: Uses `JSON`
166
172
 
167
173
  For PostgreSQL with application-specific enum types, you can override:
168
174
 
169
175
  ```python
170
176
  from enum import StrEnum
177
+ from brussels.base import DataclassBase
171
178
  from sqlalchemy import ARRAY
172
179
  from sqlalchemy.dialects.postgresql import ENUM
180
+ from sqlalchemy.orm import Mapped, mapped_column
173
181
 
174
182
  class AppScope(StrEnum):
175
183
  READ = "resource:read"
176
184
  WRITE = "resource:write"
177
185
  ADMIN = "admin"
178
186
 
179
- class User(Base):
187
+ class User(DataclassBase):
180
188
  __tablename__ = "users"
181
189
 
182
190
  id: Mapped[int] = mapped_column(primary_key=True)
@@ -203,16 +211,18 @@ Example structure:
203
211
  ```python
204
212
  from datetime import datetime
205
213
  from uuid import UUID
214
+ from brussels.base import DataclassBase
215
+ from brussels.mixins import PrimaryKeyMixin, TimestampMixin
216
+ from brussels.types import DateTimeUTC, Json
206
217
  from sqlalchemy import ForeignKey
207
218
  from sqlalchemy.orm import Mapped, mapped_column, relationship
208
- from belgie_alchemy import Base, PrimaryKeyMixin, TimestampMixin, DateTimeUTC, Scopes
209
219
 
210
- class User(Base, PrimaryKeyMixin, TimestampMixin):
220
+ class User(DataclassBase, PrimaryKeyMixin, TimestampMixin):
211
221
  __tablename__ = "users"
212
222
 
213
223
  email: Mapped[str] = mapped_column(unique=True, index=True)
214
224
  email_verified: Mapped[bool] = mapped_column(default=False)
215
- scopes: Mapped[list[str] | None] = mapped_column(Scopes, default=None)
225
+ scopes: Mapped[list[str] | None] = mapped_column(Json, default=None)
216
226
 
217
227
  accounts: Mapped[list["Account"]] = relationship(
218
228
  back_populates="user",
@@ -220,7 +230,7 @@ class User(Base, PrimaryKeyMixin, TimestampMixin):
220
230
  init=False,
221
231
  )
222
232
 
223
- class Account(Base, PrimaryKeyMixin, TimestampMixin):
233
+ class Account(DataclassBase, PrimaryKeyMixin, TimestampMixin):
224
234
  __tablename__ = "accounts"
225
235
 
226
236
  user_id: Mapped[UUID] = mapped_column(
@@ -0,0 +1,7 @@
1
+ belgie_alchemy/__init__.py,sha256=Qkyc0eCsadaCn-AxJjAu4BI2x31xTNZ2QV0J9n0oVG4,164
2
+ belgie_alchemy/adapter.py,sha256=30ePooceD1O40WpODfEycxc4KaOKx_71GiCJqqF1rRE,10305
3
+ belgie_alchemy/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ belgie_alchemy/settings.py,sha256=0zK-GDEVzmI3efEceWGV7H3jieW63gqZHVJ4vgJVlMM,4991
5
+ belgie_alchemy-0.2.0.dist-info/WHEEL,sha256=5DEXXimM34_d4Gx1AuF9ysMr1_maoEtGKjaILM3s4w4,80
6
+ belgie_alchemy-0.2.0.dist-info/METADATA,sha256=g22uQIZflLHsp7qZX_SBmJlK6WjdRps9wrETPKp476Q,7387
7
+ belgie_alchemy-0.2.0.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: uv 0.9.28
2
+ Generator: uv 0.9.29
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
File without changes
File without changes