22
33[ ![ PyPI - Version] ( https://img.shields.io/pypi/v/sqlalchemy-memory )] ( https://pypi.org/project/sqlalchemy-memory/ )
44[ ![ CI] ( https://github.com/rundef/sqlalchemy-memory/actions/workflows/ci.yml/badge.svg )] ( https://github.com/rundef/sqlalchemy-memory/actions/workflows/ci.yml )
5+ [ ![ Documentation] ( https://app.readthedocs.org/projects/sqlalchemy-memory/badge/?version=latest )] ( https://sqlalchemy-memory.readthedocs.io/en/latest/ )
56[ ![ PyPI - Downloads] ( https://img.shields.io/pypi/dm/sqlalchemy-memory )] ( https://pypistats.org/packages/sqlalchemy-memory )
67
78
@@ -34,6 +35,7 @@ Data is kept purely in RAM and is **volatile**: it is **not persisted across app
3435- ** SQLAlchemy 2.0 support** : ORM & Core expressions, sync & async modes
3536- ** Zero I/O overhead** : pure in‑RAM storage (` dict ` /` list ` under the hood)
3637- ** Commit/rollback support**
38+ - ** Index support** : indexes are recognized and used for faster lookups
3739- ** Merge and ` get() ` support** : like real SQLAlchemy behavior
3840
3941## Installation
@@ -42,104 +44,10 @@ Data is kept purely in RAM and is **volatile**: it is **not persisted across app
4244pip install sqlalchemy-memory
4345```
4446
45- ## Quickstart
47+ ## Documentation
4648
47- ``` python
48- from sqlalchemy import create_engine, select
49- from sqlalchemy.orm import sessionmaker, declarative_base, Mapped, mapped_column
50- from sqlalchemy_memory import MemorySession
49+ [ See the official documentation for usage examples] ( https://sqlalchemy-memory.readthedocs.io/en/latest/ )
5150
52- engine = create_engine(" memory://" )
53- Session = sessionmaker(
54- engine,
55- class_ = MemorySession,
56- expire_on_commit = False ,
57- )
58-
59- Base = declarative_base()
60-
61- class Item (Base ):
62- __tablename__ = " items"
63- id : Mapped[int ] = mapped_column(primary_key = True )
64- name: Mapped[str ] = mapped_column()
65- def __repr__ (self ):
66- return f " Item(id= { self .id} name= { self .name} ) "
67-
68- Base.metadata.create_all(engine)
69-
70- # Use just like any other SQLAlchemy engine:
71- session = Session()
72-
73- # Add & commit
74- item = Item(id = 1 , name = " foo" )
75- session.add(item)
76- session.commit()
77-
78- # Query (no SQL under the hood: objects come straight back)
79- items = session.scalars(select(Item)).all()
80- print (" Items" , items)
81- assert items[0 ] is item
82- assert items[0 ].name == " foo"
83-
84- # Delete & commit
85- session.delete(item)
86- session.commit()
87-
88- # Confirm gone
89- assert session.scalars(select(Item)).all() == []
90- ```
91-
92- ## Quickstart (async)
93-
94- ``` python
95- import asyncio
96- from sqlalchemy import select
97- from sqlalchemy.ext.asyncio import create_async_engine
98- from sqlalchemy.orm import sessionmaker, declarative_base, Mapped, mapped_column
99- from sqlalchemy_memory import MemorySession, AsyncMemorySession
100-
101- engine = create_async_engine(" memory+asyncio://" )
102- Session = sessionmaker(
103- engine,
104- class_ = AsyncMemorySession,
105- sync_session_class = MemorySession,
106- expire_on_commit = False ,
107- )
108-
109- Base = declarative_base()
110-
111- class Item (Base ):
112- __tablename__ = " items"
113- id : Mapped[int ] = mapped_column(primary_key = True )
114- name: Mapped[str ] = mapped_column()
115-
116- def __repr__ (self ):
117- return f " Item(id= { self .id} name= { self .name} ) "
118-
119- Base.metadata.create_all(engine.sync_engine)
120-
121- async def main ():
122- async with Session() as session:
123- # Add & commit
124- item = Item(id = 1 , name = " foo" )
125- session.add(item)
126- await session.commit()
127-
128- # Query (no SQL under the hood: objects come straight back)
129- items = (await session.scalars(select(Item))).all()
130- print (" Items" , items)
131- assert items[0 ] is item
132- assert items[0 ].name == " foo"
133-
134- # Delete & commit
135- await session.delete(item)
136- await session.commit()
137-
138- # Confirm gone
139- assert (await session.scalars(select(Item))).all() == []
140-
141- asyncio.run(main())
142- ```
14351
14452## Status
14553
@@ -155,11 +63,13 @@ Coming soon:
15563
15664- Joins and relationships (limited)
15765
66+ - Compound indexes
67+
15868- Better expression support in ` update(...).values() ` (e.g., +=)
15969
16070## Testing
16171
162- Simply run ` pytest `
72+ Simply run ` make tests `
16373
16474## License
16575
0 commit comments