@@ -67,7 +67,7 @@ If you maintain or use a different library and would like it to support `ormar`
6767Ormar 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
118118import 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
133136For 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
164167from typing import Optional
165168
166- import databases
167169import pydantic
168170
169171import ormar
170172import sqlalchemy
173+ from ormar import DatabaseConnection
171174
172- DATABASE_URL = " sqlite:///db.sqlite"
175+ DATABASE_URL = " sqlite+aiosqlite :///db.sqlite"
173176base_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/
0 commit comments