Skip to content

Commit 0129c1a

Browse files
authored
Fix/readme sqlalchemy update (#1520)
* update readme too * update readme remove pg extension as not maintained
1 parent 8c9f001 commit 0129c1a

2 files changed

Lines changed: 19 additions & 17 deletions

File tree

README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ If you maintain or use a different library and would like it to support `ormar`
6767
Ormar is built with:
6868

6969
* [`sqlalchemy core`][sqlalchemy-core] for query building.
70-
* [`databases`][databases] for cross-database async support.
70+
* [`sqlalchemy async`][sqlalchemy-async] for cross-database async support.
7171
* [`pydantic`][pydantic] for data validation.
7272

7373
### License
@@ -116,18 +116,21 @@ For tests and basic applications the `sqlalchemy` is more than enough:
116116
# note this is just a partial snippet full working example below
117117
# 1. Imports
118118
import sqlalchemy
119-
import databases
119+
import ormar
120+
from ormar import DatabaseConnection
120121

121122
# 2. Initialization
122-
DATABASE_URL = "sqlite:///db.sqlite"
123-
database = databases.Database(DATABASE_URL)
124-
metadata = sqlalchemy.MetaData()
123+
DATABASE_URL = "sqlite+aiosqlite:///db.sqlite"
124+
base_ormar_config = ormar.OrmarConfig(
125+
metadata=sqlalchemy.MetaData(),
126+
database=DatabaseConnection(DATABASE_URL),
127+
)
125128

126129
# Define models here
127130

128131
# 3. Database creation and tables creation
129-
engine = sqlalchemy.create_engine(DATABASE_URL)
130-
metadata.create_all(engine)
132+
engine = sqlalchemy.create_engine(DATABASE_URL.replace('+aiosqlite', ''))
133+
base_ormar_config.metadata.create_all(engine)
131134
```
132135

133136
For a sample configuration of alembic and more information regarding migrations and
@@ -163,17 +166,16 @@ Note that you can find the same script in examples folder on github.
163166
```python
164167
from typing import Optional
165168

166-
import databases
167169
import pydantic
168170

169171
import ormar
170172
import sqlalchemy
173+
from ormar import DatabaseConnection
171174

172-
DATABASE_URL = "sqlite:///db.sqlite"
175+
DATABASE_URL = "sqlite+aiosqlite:///db.sqlite"
173176
base_ormar_config = ormar.OrmarConfig(
174-
database=databases.Database(DATABASE_URL),
175177
metadata=sqlalchemy.MetaData(),
176-
engine=sqlalchemy.create_engine(DATABASE_URL),
178+
database=DatabaseConnection(DATABASE_URL),
177179
)
178180

179181

@@ -205,9 +207,11 @@ class Book(ormar.Model):
205207
# create the database
206208
# note that in production you should use migrations
207209
# note that this is not required if you connect to existing database
210+
# create a sync engine for table creation
211+
sync_engine = sqlalchemy.create_engine(DATABASE_URL.replace('+aiosqlite', ''))
208212
# just to be sure we clear the db before
209-
base_ormar_config.metadata.drop_all(base_ormar_config.engine)
210-
base_ormar_config.metadata.create_all(base_ormar_config.engine)
213+
base_ormar_config.metadata.drop_all(sync_engine)
214+
base_ormar_config.metadata.create_all(sync_engine)
211215

212216

213217
# all functions below are divided into functionality categories
@@ -566,7 +570,7 @@ for func in [
566570
asyncio.run(with_connect(func))
567571

568572
# drop the database tables
569-
base_ormar_config.metadata.drop_all(base_ormar_config.engine)
573+
base_ormar_config.metadata.drop_all(sync_engine)
570574
```
571575

572576
## Ormar Specification
@@ -672,7 +676,7 @@ Signals allow to trigger your function for a given event on a given Model.
672676

673677

674678
[sqlalchemy-core]: https://docs.sqlalchemy.org/en/latest/core/
675-
[databases]: https://github.com/encode/databases
679+
[sqlalchemy-async]: https://docs.sqlalchemy.org/en/20/orm/extensions/asyncio.html
676680
[pydantic]: https://pydantic-docs.helpmanual.io/
677681
[encode/orm]: https://github.com/encode/orm/
678682
[alembic]: https://alembic.sqlalchemy.org/en/latest/

docs/index.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ Ormar remains sql dialect agnostic - so only columns working in all supported ba
5959

6060
It's relatively easy to implement columns for specific dialects as an extensions of ormar.
6161

62-
Postgres specific columns implementation: [`ormar-postgres-extensions`](https://github.com/tophat/ormar-postgres-extensions)
63-
6462
If you maintain or use a different library and would like it to support `ormar` let us know how we can help.
6563

6664
### Dependencies

0 commit comments

Comments
 (0)