# Sqlalchemy bulk insert helper
A simple helper for bulk insert data with sqlalchemy
usage:
Let's assume we have a session and model
```python
from sqlalchemy import create_engine, INTEGER, String, Column
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
metadata = Base.metadata
sess = sessionmaker(bind=create_engine("DB_URL"))()
class User(Base):
__tablename__ = 'user'
id = Column(INTEGER, primary_key=True, autoincrement=True)
name = Column(String(100))
```
create users for simple which need to be inserted into db
```
users = [User(name=i) for i in ('Thor', 'Stark', 'Rogers', 'Scarlet Witch', 'Strange')]
```
And we can insert users with following code:
```python
from sa_insert_helper import bulk_insert
with bulk_insert(session=sess, model=User, n=1000) as bi:
for u in users:
bi.insert(u)
```
A simple helper for bulk insert data with sqlalchemy
usage:
Let's assume we have a session and model
```python
from sqlalchemy import create_engine, INTEGER, String, Column
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker
Base = declarative_base()
metadata = Base.metadata
sess = sessionmaker(bind=create_engine("DB_URL"))()
class User(Base):
__tablename__ = 'user'
id = Column(INTEGER, primary_key=True, autoincrement=True)
name = Column(String(100))
```
create users for simple which need to be inserted into db
```
users = [User(name=i) for i in ('Thor', 'Stark', 'Rogers', 'Scarlet Witch', 'Strange')]
```
And we can insert users with following code:
```python
from sa_insert_helper import bulk_insert
with bulk_insert(session=sess, model=User, n=1000) as bi:
for u in users:
bi.insert(u)
```
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file sa-insert-helper-0.0.1.tar.gz.
File metadata
- Download URL: sa-insert-helper-0.0.1.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/38.2.4 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/2.7.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b56291e36b967249a4e134ec0d24b89469362859689098a8f701d0bed6ce8e85
|
|
| MD5 |
798d002036cec14425a6bd3a61e4f1c2
|
|
| BLAKE2b-256 |
9f7f5803d9540e5cb0584248cd2db20ac2454598987261685627285750910db5
|