peewee_seed is simple data seeder using peewee.
Project description
# peewee_seed
peewee_seed is a seed library which provides initial data to database using peewee.
With reference to the [Django fixture](https://docs.djangoproject.com/en/2.1/howto/initial-data/)
[![CircleCI](https://circleci.com/gh/takehaya/peewee_seeds.svg?style=svg)](https://circleci.com/gh/takehaya/peewee_seeds)
[![PyPI version](https://badge.fury.io/py/peewee-seed.svg)](https://badge.fury.io/py/peewee-seed)
## usage
### simple seeds
- file envs
```
/myapp
__init__.py
seeds_entry.py
models.py
/fixtures
accounts.yaml
```
``` yaml
# accounts.yaml
- model : myapp.models.Account
id: 1
fields:
first_name: John
last_name: Smith
age: 20
```
```python
# models.py
from peewee import CharField
from peewee import IntegerField
from peewee import Model
from peewee import SqliteDatabase
database = SqliteDatabase(":memory:", pragmas={"foregin_keys": 1})
class BaseModel(Model):
class Meta(object):
database = database
class Account(BaseModel):
first_name = CharField(null=False)
last_name = CharField(null=False)
age = IntegerField(null=True)
```
- seeds entry file
``` python
# seeds_entry.py
from peewee_seeds import PeeweeSeeds
from myapp.models import database
def main():
path = '/path/to/fixtures'
# seeds instance
seeds = PeeweeSeeds(database, path, ['accounts.yaml'])
# load fixture for create table
seeds.create_table_all()
# load fixture for db input
seeds.db_data_input()
if __name__ == '__main__':
main()
```
- Run command
```
python seeds_entroy.py
```
### other example
```python
from peewee_seeds import PeeweeSeeds
from myapp.models import database
# seeds instance
seeds = PeeweeSeeds()
# set path
seeds.set_path('/path/to/fixtures')
# set use fixture name
seeds.set_fixture_files(['accounts.yaml', 'pictures.yaml'])
# loading fixture file data
fixtures_row_data = seeds.load_fixture_files()
# fixture purification
fields, models_namelist = seeds.load_fixture(fixtures_row_data[0])
# fixtures purification
fields, models_namelist = seeds.load_fixtures(fixtures_row_data)
# set database session
seeds.set_database(database)
# base on fixtures, create tables
seeds.create_table_all()
# fixtures data to db input
seeds.db_data_input(fixtures_row_data)
# base on fixtures, drop tables
seeds.drop_table_all()
```
peewee_seed is a seed library which provides initial data to database using peewee.
With reference to the [Django fixture](https://docs.djangoproject.com/en/2.1/howto/initial-data/)
[![CircleCI](https://circleci.com/gh/takehaya/peewee_seeds.svg?style=svg)](https://circleci.com/gh/takehaya/peewee_seeds)
[![PyPI version](https://badge.fury.io/py/peewee-seed.svg)](https://badge.fury.io/py/peewee-seed)
## usage
### simple seeds
- file envs
```
/myapp
__init__.py
seeds_entry.py
models.py
/fixtures
accounts.yaml
```
``` yaml
# accounts.yaml
- model : myapp.models.Account
id: 1
fields:
first_name: John
last_name: Smith
age: 20
```
```python
# models.py
from peewee import CharField
from peewee import IntegerField
from peewee import Model
from peewee import SqliteDatabase
database = SqliteDatabase(":memory:", pragmas={"foregin_keys": 1})
class BaseModel(Model):
class Meta(object):
database = database
class Account(BaseModel):
first_name = CharField(null=False)
last_name = CharField(null=False)
age = IntegerField(null=True)
```
- seeds entry file
``` python
# seeds_entry.py
from peewee_seeds import PeeweeSeeds
from myapp.models import database
def main():
path = '/path/to/fixtures'
# seeds instance
seeds = PeeweeSeeds(database, path, ['accounts.yaml'])
# load fixture for create table
seeds.create_table_all()
# load fixture for db input
seeds.db_data_input()
if __name__ == '__main__':
main()
```
- Run command
```
python seeds_entroy.py
```
### other example
```python
from peewee_seeds import PeeweeSeeds
from myapp.models import database
# seeds instance
seeds = PeeweeSeeds()
# set path
seeds.set_path('/path/to/fixtures')
# set use fixture name
seeds.set_fixture_files(['accounts.yaml', 'pictures.yaml'])
# loading fixture file data
fixtures_row_data = seeds.load_fixture_files()
# fixture purification
fields, models_namelist = seeds.load_fixture(fixtures_row_data[0])
# fixtures purification
fields, models_namelist = seeds.load_fixtures(fixtures_row_data)
# set database session
seeds.set_database(database)
# base on fixtures, create tables
seeds.create_table_all()
# fixtures data to db input
seeds.db_data_input(fixtures_row_data)
# base on fixtures, drop tables
seeds.drop_table_all()
```
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
peewee_seed-0.1.3.tar.gz
(4.2 kB
view hashes)
Built Distribution
Close
Hashes for peewee_seed-0.1.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 58d364d1f143689e40bca5b73a6c9c6c6dc68bab80f95273570de29e8bc4214d |
|
MD5 | 73e3dcac076037845f45c18be7a5be68 |
|
BLAKE2b-256 | ba468b4c5d0bb051a45c14e0ea2fd9d465ce25489d4ef5a1c2c653b06c89247d |