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/)
[](https://circleci.com/gh/takehaya/peewee_seeds)
[](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 PeeweeSeed
from myapp.models import database
def main():
path = '/path/to/fixtures'
# seeds instance
seeds = PeeweeSeed(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_seed import PeeweeSeed
from myapp.models import database
# seeds instance
seeds = PeeweeSeed()
# 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()
```
### direct inputdata seed
``` python
# body is dict data
# create & seed
seed = PeeweeSeed(db)
_, models = seed.load_fixtures([body])
seed.create_table_all(models)
seed.db_data_input([body])
# body is modelpath(same to fixtures)
# drop
seed = PeeweeSeed(db)
models = body["models"]
seed.drop_table_all(models)
```
#### error: Foreign key constraint
```python
# seed
seed.db_data_input([body], foreign_key_checks=True)
# db drop
seed.drop_table_all(models, foreign_key_checks=True)
```
Metadata
Release files for peewee-seed 0.1.8
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| peewee_seed-0.1.8-py3-none-any.whl | Python 3 | none | any | Details for peewee_seed-0.1.8-py3-none-any.whl |
Release files / peewee_seed-0.1.8-py3-none-any.whl
| Download URL | peewee_seed-0.1.8-py3-none-any.whl |
|---|---|
| Size | 5.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0ab577209eb73873449f4d61a145edd8592b16720967c3e3bd43fabcb8cb78bc
|
|
BLAKE2b-256 checksum How to use checksums |
b7426b1dfc6cc43c27af52640956053156e57d0c6d70349674f70c72994e7e3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.27.0 CPython/3.6.4
|
Security for peewee-seed 0.1.8
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.