Package provides utilities for managing fixture data python applications. It offers a convenient way to populate database tables with predefined data.
Project description
Masonite Fixtures
The masonite-fixtures
package provides utilities for managing fixture data python applications. It offers a convenient way to populate database tables with predefined data.
Installation
You can install masonite-fixtures
via pip:
pip install masonite-fixtures
Features
- Initialize fixture data for database tables effortlessly.
- Automatically create database tables based on the schema of the fixture model.
- Populate database tables with data defined in the fixture model using either
get_rows
method orrows
property. - Enable query logging for debugging and monitoring database interactions.
Usage
To use the masonite-fixtures
package, follow these steps:
- Import your model class that implements the
FixtureMixin
. - Mix the
FixtureMixin
into your model class.
That's it.
3. Optionally, set the __log_queries__
attribute to True
to enable query logging.
Example:
from typing import Any
from masoniteorm.models import Model
from masonite_fixtures import FixtureMixin
# Example using get_rows method:
class User(Model, FixtureMixin):
def get_rows(self) -> list[dict[str, Any]]:
return [
{"name": "John", "age": 30},
{"name": "Alice", "age": 25},
# Add more rows as needed
]
# Example using rows attribute:
class User(Model, FixtureMixin):
rows: list[dict[str, Any]] = [
{"name": "John", "age": 30},
{"name": "Alice", "age": 25},
# Add more rows as needed
]
Thats it. You can now use the model as you would any other masoniteorm model.
Important
If the number of rows defined in the rows
attribute or get_rows
property of the fixture model class exceeds the number of rows stored in the actual database cache for the fixture, the fixture will reset the database table and reseed the fixture data.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for masonite_fixtures-0.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b7fca56e37086f78ad83ad3c192e500c4546732dee3db3289ade004f447998ae |
|
MD5 | 9f1487268b0f2546fb747474d41ae4ea |
|
BLAKE2b-256 | aa626a3c3cd66b269b0a9b977f2927f8058ac49b81f732b632185ceff88f5e40 |