Commit cf02fd5
committed
Add support for RETURNING in SQLAlchemy dialect
This will enable the usage of `FetchedValue()` as server side default
for primary keys in the declarative model.
```python
import random
from sqlalchemy import create_engine, inspect, func, Column, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
from sqlalchemy.schema import FetchedValue
engine = create_engine(
"crate://",
connect_args={
"username": "crate",
},
)
Session = sessionmaker(bind=engine)
Base = declarative_base(bind=engine)
class Log(Base):
__tablename__ = "logs"
__table_args__ = {"schema": "doc"}
__mapper_args__ = {"exclude_properties": ["id"]}
id = Column("_id", String, server_default=FetchedValue(), primary_key=True)
ts = Column(DateTime, server_default=func.current_timestamp())
level = Column(String)
message = Column(String)
if __name__ == "__main__":
o = Log(level="info", message="Hello World")
session = Session()
session.add(o)
session.commit()
print(f"{o.id=}, {o.ts=}, {o.level=}, {o.message=}")
```1 parent 1f3189e commit cf02fd5
File tree
4 files changed
+55
-3
lines changed- docs
- src/crate/client/sqlalchemy
4 files changed
+55
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
8 | 14 | | |
9 | 15 | | |
10 | 16 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
198 | 198 | | |
199 | 199 | | |
200 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
201 | 240 | | |
202 | 241 | | |
203 | 242 | | |
| |||
336 | 375 | | |
337 | 376 | | |
338 | 377 | | |
339 | | - | |
340 | 378 | | |
341 | 379 | | |
342 | 380 | | |
343 | | - | |
344 | 381 | | |
345 | 382 | | |
346 | 383 | | |
| |||
544 | 581 | | |
545 | 582 | | |
546 | 583 | | |
547 | | - | |
| 584 | + | |
548 | 585 | | |
549 | 586 | | |
550 | 587 | | |
| |||
557 | 594 | | |
558 | 595 | | |
559 | 596 | | |
| 597 | + | |
560 | 598 | | |
561 | 599 | | |
562 | 600 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
180 | 187 | | |
181 | 188 | | |
182 | 189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
| 168 | + | |
168 | 169 | | |
169 | 170 | | |
170 | 171 | | |
| |||
0 commit comments