### Edgy Quick Start Example Source: https://github.com/dymmond/edgy/blob/main/docs/index.md Example of how to start with Edgy. The code is not shown on this page; it is included from an external file. The surrounding text notes that if no tablename is provided in the Meta class, Edgy automatically generates the table name by pluralising the class name. ```python {!> ../docs_src/quickstart/example1.py!} ``` -------------------------------- ### Project structure for migration examples Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md Shows the directory layout used in the migration examples. The structure includes the myproject directory with apps, configs, and test files. ```shell . ├── README.md ├── .gitignore └── myproject ├── __init__.py ├── apps │ ├── __init__.py │ └── accounts │ ├── __init__.py │ ├── tests.py │ └── v1 │ ├── __init__.py │ ├── schemas.py │ ├── urls.py │ └── controllers.py ├── configs │ ├── __init__.py │ ├── development │ │ ├── __init__.py │ │ └── settings.py │ ├── settings.py │ └── testing │ ├── __init__.py │ └── settings.py ├── main.py ├── serve.py ├── utils.py ├── tests │ ├── __init__.py │ └── test_app.py └── urls.py ``` -------------------------------- ### Example: inspectdb with PostgreSQL connection string Source: https://github.com/dymmond/edgy/blob/main/docs/inspectdb.md Example command that generates reflected models from a PostgreSQL database and writes them to `models.py`. ```shell edgy inspectdb --database "postgres+asyncpg://user:password@localhost:5432/my_db" > models.py ``` -------------------------------- ### main.py with Edgy migration setup Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/discovery.md The main.py file contains the Edgy migration setup. The actual content is included from an external file and is not shown on this page. ```python {!> ../docs_src/commands/discover.py !} ``` -------------------------------- ### Install Edgy test client with pip Source: https://github.com/dymmond/edgy/blob/main/docs/testing/test-client.md Installs the Edgy test client with its required dependencies. ```bash $ pip install edgy[test] ``` -------------------------------- ### Install Edgy with pip install Source: https://github.com/dymmond/edgy/blob/main/README.md Installs the core `edgem ```shell $ pip install edgy ``` -------------------------------- ### Build, serve, and prepare documentation Source: https://github.com/dymmond/edgy/blob/main/docs/contributing.md Generate build-ready markdown documentation, start a live-reload preview, and build the static docs site. ```shell hatch run docs:prepare ``` ```shell hatch run docs:serve ``` ```shell hatch run docs:build ``` -------------------------------- ### Run edgy migrate with explicit app Source: https://github.com/dymmond/edgy/blob/main/docs/getting-started/first-migration-cycle.md If auto-discovery fails, start commands with `--app` to specify the app module. Example: `edgy --app myproject.main migrate`. ```shell $ edgy --app myproject.main migrate ``` -------------------------------- ### Install pre-commit hook Source: https://github.com/dymmond/edgy/blob/main/docs/contributing.md Enable the pre-commit hook for the project. Run inside the clone. ```shell hatch run pre-commit install ``` -------------------------------- ### Example database URL Source: https://github.com/dymmond/edgy/blob/main/docs/testing/test-client.md An example database URL. The DatabaseTestClient uses the database name 'my_db' and automatically targets a test database named 'test_my_db'. ```bash DATABASE_URL = "postgresql+asyncpg://postgres:postgres@localhost:5432/my_db" ``` -------------------------------- ### Start default Edgy shell Source: https://github.com/dymmond/edgy/blob/main/docs/settings.md Starts the default Edgy shell using the custom settings module. ```shell $ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy shell ``` -------------------------------- ### Install Edgy with MSSQL support, description: Source: https://github.com/dymmond/edgy/blob/main/README.md Installing the edgy[mssql] package enables SQL Server database support. ```shell $ pip install edgy[mssql] ``` -------------------------------- ### Snapshotting example Source: https://github.com/dymmond/edgy/blob/main/docs/contenttypes/intro.md Demonstrates how to track when an object is created or updated using ContentType. ```python {!> ../docs_src/contenttypes/snapshotting.py !} ``` -------------------------------- ### Install Edgy with Postgres support Source: https://github.com/dymmond/edgy/blob/main/docs/getting-started/install-and-first-query.md Installs Edgy with Postgres support using pip. ```shell $ pip install edgy[postgres] ``` -------------------------------- ### Define your first Edgy model Source: https://github.com/dymmond/edgy/blob/main/docs/getting-started/install-and-first-query.md This example creates a model, creates a record, and reads it back. Use ipython to run await directly. ```python {!> ../docs_src/quickstart/example1.py !} ``` -------------------------------- ### Install Edgy with SQLite support Source: https://github.com/dymmond/edgy/blob/main/docs/getting-started/install-and-first-query.md Installs Edgy with SQLite support using pip. ```shell $ pip install edgy[sqlite] ``` -------------------------------- ### Install IPython Source: https://github.com/dymmond/edgy/blob/main/docs/shell.md Install IPython, one of the interactive shells supported by Edgy's shell. Use this to enable the default shell or the IPython kernel. ```shell $ pip install ipython ``` -------------------------------- ### Ravyn API Response Example Source: https://github.com/dymmond/edgy/blob/main/docs/index.md Example JSON response from the /create API endpoint, showing the expected format with fields id, name, email, language, and description. ```json { "id": 1, "name": "Edgy", "email": "edgy@ravyn.dev", "language": "EN", "description": "A description", } ``` -------------------------------- ### Example project structure Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md A typical project layout for an Edgy application, showing the placement of models, settings, and main files. ```shell . ├── README.md ├── .gitignore └── myproject ├── __init__.py ├── apps │ ├── __init__.py │ └── accounts │ ├── __init__.py │ ├── tests.py │ ├── models.py │ └── v1 │ ├── __init__.py │ ├── schemas.py │ ├── urls.py │ └── controllers.py ├── configs │ ├── __init__.py │ ├── development │ │ ├── __init__.py │ │ └── settings.py │ ├── settings.py │ └── testing │ ├── __init__.py │ └── settings.py ├── main.py ├── serve.py ├── utils.py ├── tests │ ├── __init__.py │ └── test_app.py └── urls.py ``` -------------------------------- ### Use a filesystem template with edgy init Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md Use a template from the filesystem by providing its path with the `-t` flag. The example uses the `singledb` template from tests. ```shell edgy --app myproject.main init -t tests/cli/custom_singledb ``` -------------------------------- ### SmallIntegerField example Source: https://github.com/dymmond/edgy/blob/main/docs/fields/index.md Shows how to use edgy.SmallIntegerField with default and gte parameters. ```python import edgy class MyModel(edgy.Model): a_number: int = edgy.SmallIntegerField(default=0) another_number: int = edgy.SmallIntegerField(gte=10) ... ``` -------------------------------- ### IntegerField example Source: https://github.com/dymmond/edgy/blob/main/docs/fields/index.md Shows how to use edgy.IntegerField with default and gte parameters. ```python import edgy class MyModel(edgy.Model): a_number: int = edgy.IntegerField(default=0) another_number: int = edgy.IntegerField(gte=10) ... ``` -------------------------------- ### Equivalent and_.from_kwargs expression Source: https://github.com/dymmond/edgy/blob/main/docs/queries/q.md Shows the equivalent expression using and_.from_kwargs for the previous Q object example. ```python await User.query.filter(and_.from_kwargs(name="Adam", email__icontains="edgy")) ``` -------------------------------- ### MarshallField source example Source: https://github.com/dymmond/edgy/blob/main/docs/marshalls.md Shows how to use MarshallField with a source that references a model field, property, or function. All values must come from the Edgy model. ```python {!> ../docs_src/marshalls/source.py !} ``` -------------------------------- ### Set up Migration object with Instance Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md Creates an Instance with a registry and optional app. The registry must be an edgy.Registry instance or an AssertionError is raised. ```python from edgy import Instance, monkay monkay.set_instance(Instance(registry=registry, app=None)) ``` -------------------------------- ### or_ - Global OR mode Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md When a single set of keyword filters or a single dict is passed, `or_` promotes previous filters into a top-level OR group. This example starts with a base filter for active users and adds a condition for emails containing 'gmail'. ```APIDOC ## or_ - Global OR mode ### Description When a single set of keyword filters or a single dict is passed, `or_` promotes previous filters into a top-level OR group. This example starts with a base filter for active users and adds a condition for emails containing 'gmail'. ### Method or_ ### Endpoint User.query.and_(active=True).or_(email__icontains="gmail") ### Parameters #### Query Parameters - **active** (bool) - Required - Filter for active users. - **email__icontains** (str) - Required - Case-insensitive substring match on email. ### Request Example ```python user_query = User.query.and_(active=True) user_query = user_query.or_(email__icontains="gmail") users = await user_query ``` ### Response #### Success Response - **users** (QuerySet) - The resulting QuerySet with rows matching (active = TRUE) OR (email ILIKE '%gmail%'). #### Response Example ```python users = await user_query ``` ``` -------------------------------- ### Create a database and query a model Source: https://github.com/dymmond/edgy/blob/main/README.md This example demonstrates how to create a SQLite database and a User model using Edgy, then create and retrieve a user. It uses the default SQLite database URL 'sqlite:///db.sqlite' and assumes you are using IPython for the await calls. The example also shows that if no table name is provided in the Meta class, the table name is automatically generated by pluralizing the class name and uses the default 'users' table. Note that using `create_all()` is not recommended for production; use a migration tool like Alembic instead. The output of the last line is `User(id=1)`. ```python import edgy from edgy import Database, Registry database = Database("sqlite:///db.sqlite ``` -------------------------------- ### Preload example with EDGY_SETTINGS_MODULE Source: https://github.com/dymmond/edgy/blob/main/docs/settings.md Set preloads to load the app instance automatically, avoiding the need to pass --app. Then run edgy shell and edgy makemigrations with the environment variable set. ```python from edgy.conf import EdgySettings class MyCustomSettings(EdgySettings): preloads = ("myproject.main",) ``` ```shell $ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy shell $ EDGY_SETTINGS_MODULE=myproject.configs.settings.MyCustomSettings edgy makemigrations ``` -------------------------------- ### Django-style filter examples Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Examples of Django-style filters using icontains and in operators. ```python users = await User.query.filter(email__icontains="foo") users = await User.query.filter(id__in=[1, 2, 3]) ``` -------------------------------- ### Initialize migration repository with edgy init Source: https://github.com/dymmond/edgy/blob/main/docs/getting-started/first-migration-cycle.md Run `edgy init` to create the migration environment once. This is the first step in the standard migration cycle. ```shell $ edgy init ``` -------------------------------- ### Initialize migration repository Source: https://github.com/dymmond/edgy/blob/main/docs/cli/commands.md Creates migration repository files (`alembic.ini`, env scripts, versions folder). Use for first-time migration setup. The `-t plain` option selects a plain template. ```shell $ edgy init ``` ```shell $ edgy init -t plain ``` -------------------------------- ### List migration templates Source: https://github.com/dymmond/edgy/blob/main/docs/cli/commands.md Shows available migration repository templates. Use before `edgy init` when choosing a template. ```shell $ edgy list-templates ``` -------------------------------- ### Install Edgy with MySQL/MariaDB support Source: https://github.com/dymmond/edgy/blob/main/README.md Installing the `edgy[mysql]` package enables MySQL and MariaDB database support. ``` $ pip: ``` -------------------------------- ### Get single record from filtered queryset Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Obtains a single record from the database by applying get() to a filtered queryset. ```python user = await User.query.filter(email="foo@bar.com").get() ``` -------------------------------- ### Run admin server with CLI Source: https://github.com/dymmond/edgy/blob/main/docs/admin/admin.md Starts the admin server. The `--create-all` flag is only for testing and should not be used with migrations. The default username is `admin` and a password is generated and printed to the console. ```bash edgy admin_serve ``` ```bash edgy --app tests.cli.main admin_serve --create-all ``` -------------------------------- ### Install PTPython Source: https://github.com/dymmond/edgy/blob/main/docs/shell.md Install PTPython, another interactive shell supported by Edgy's shell. Use this to enable the ptpython kernel. ```shell $ pip install ptpython ``` -------------------------------- ### First migration in a new project Source: https://github.com/dymmond/edgy/blob/main/docs/cli/commands.md Typical workflow for setting up migrations in a new project: initialize, generate initial migration, and apply it. ```shell $ edgy init ``` ```shell $ edgy makemigrations -m "Initial schema" ``` ```shell $ edgy migrate ``` -------------------------------- ### Include marker for test example Source: https://github.com/dymmond/edgy/blob/main/docs/testing/test-client.md This is a literal include marker for an external example file. The file is not part of this page, so no code is extracted. ```python {!> ../docs_src/testing/testclient/tests.py !} ``` -------------------------------- ### Pre-initialize environments with hatch env Source: https://github.com/dymmond/edgy/blob/main/docs/contributing.md Pre-initialize the development environments. Run from the cloned project directory. This is the recommended way, but you can also use scripts/install for your own virtual environment. ```shell cd edgy hatch env create hatch env create test hatch env create docs ``` -------------------------------- ### Many-to-One Relation Example Source: https://github.com/dymmond/edgy/blob/main/docs/queries/many-to-one.md Example model definitions for a many-to-one relation, likely showing Team and TeamMember models with a ForeignKey and related_name. ```python {!> ../docs_src/queries/manytoone/example.py !} ``` -------------------------------- ### Minimal Test Client Setup Source: https://github.com/dymmond/edgy/blob/main/docs/testing/index.md Sets up a DatabaseTestClient with a PostgreSQL database, dropping the database after tests. Uses force_rollback to isolate tests and avoid touching the development database. ```python import edgy from edgy.testclient import DatabaseTestClient database = DatabaseTestClient( "postgresql+asyncpg://postgres:postgres@localhost:5432/my_db", drop_database=True, ) models = edgy.Registry(database=edgy.Database(database, force_rollback=True)) async def test_query_roundtrip(): async with database: async with models: # run your model operations here ... ``` -------------------------------- ### Start interactive shell Source: https://github.com/dymmond/edgy/blob/main/docs/cli/commands.md Starts an interactive shell with imported models and defaults. The `--kernel ptpython` option selects the ptpython kernel. ```shell $ edgy shell ``` ```shell $ edgy shell --kernel ptpython ``` -------------------------------- ### Typical user and post creation with RefForeignKey Source: https://github.com/dymmond/edgy/blob/main/docs/reference-foreignkey.md Shows the standard way to create users and posts, associating posts with a user. This is the conventional approach that RefForeignKey offers an alternative to. ```python # Create the user user = await User.query.create(name="Edgy") # Create posts and associate with the user await Post.query.create(user=user, comment="A comment") await Post.query.create(user=user, comment="Another comment") await Post.query.create(user=user, comment="A third comment") ``` -------------------------------- ### Prepare test database with docker compose Source: https://github.com/dymmond/edgy/blob/main/docs/contributing.md Set up the database environment for tests. Must be run once before testing. ```shell # only once required until stopped or db leftovers clogging up docker compose up -d ``` -------------------------------- ### Importing CASCADE, SET_NUTRITION:list[User] = edg. Source: https://github.com/dymmond/edgy/blob/main/docs/fields/index.md importing the three constants used with `on_delete` from the `edg. ```Thema:list[User] = edg. from edg. ``` -------------------------------- ### Define a model without field typing Source: https://github.com/dymmond/edgy/blob/main/README.md This example shows how to field typing is optional and does not affect validation; the actual validation is not affected by whether or not you type the attributes. The example uses a User model with an ```python import edts ``` -------------------------------- ### List Edgy options with edgy --help Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md Shows the available Edgy command-line options. ```shell $ edgy --help ``` -------------------------------- ### Embeddable Models Example Source: https://github.com/dymmond/edgy/blob/main/docs/embedding.md Shows how to embed models automatically using class attributes. Fields are copied with a prefix, and fields with inherit=False are excluded. The example defines InheritableModel, NonInheritableModel, MyModel, and AnotherModel. ```python from typing import ClassVar import edgy class InheritableModel(edgy.Model): first_name: str = edgy.CharField(max_length=255) last_name: str = edgy.CharField(max_length=255) class Meta: abstract = True class NonInheritableModel(edgy.Model): age: int = edgy.IntegerField() class Meta: abstract = True inherit = False class MyModel(edgy.Model): model1: ClassVar[InheritableModel] = InheritableModel # ClassVar is optional model2 = NonInheritableModel class AnotherModel(MyModel): pass # NonInheritableModel is gone ``` -------------------------------- ### Get or create with User.query.get_or_create Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Queries the User model by email and creates a new instance with the provided defaults if none exists. Returns a tuple of (instance, created). Can raise MultipleObjectsReturned because it internally performs a get. ```python user, created = await User.query.get_or_create( email="foo@bar.com", defaults={"is_active": False, "first_name": "Foo"} ) ``` -------------------------------- ### Project structure after edgy init Source: https://github.com/dymmond/edgy/blob/main/docs/migrations/migrations.md Shows the project structure after running `edgy init`. The migrations folder and its contents are automatically generated and tailored to Edgy's requirements. ```shell . └── README.md └── .gitignore ├── migrations │ ├── alembic.ini │ ├── env.py │ ├── README │ ├── script.py.mako │ └── versions └── myproject ├── __init__.py ├── apps │ ├── __init__.py │ └── accounts │ ├── __init__.py │ ├── tests.py │ └── v1 │ ├── __init__.py │ ├── schemas.py │ ├── urls.py │ └── controllers.py ├── configs │ ├── __init__.py │ ├── development │ │ ├── __init__.py │ │ └── settings.py │ ├── settings.py │ └── testing │ ├── __init__.py │ └── settings.py ├── main.py ├── serve.py ├── utils.py ├── tests │ ├── __init__.py │ └── test_app.py └── urls.py ``` -------------------------------- ### Edgy with Ravyn Integration Example Source: https://github.com/dymmond/edgy/blob/main/docs/index.md Example of integrating Edgy with the Ravyn framework. The code is not shown on this page; it is included from an external file. The surrounding text mentions that Edgy is fully Pydantic, allowing direct tasks. ```python {!> ../docs_src/quickstart/ravyn.py!} ``` -------------------------------- ### Query with classic .using(schema='main') Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Query the 'main' schema by repeatedly calling `.using(schema="main")` on each query. ```python # Using the 'main' schema User.query.using(schema="main").all() User.query.using(schema="main").filter(email__icontains="user@example.com") User.query.using(schema="main").get(pk=1) ``` -------------------------------- ### Full example: atomic lock-and-update and skip_locked batch Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md End-to-end example showing atomic lock-and-update with select_for_update() and a batch operation using skip_locked. The first transaction locks a user row and updates it; the second locks a batch of active users, skipping locked rows. ```python async with database.transaction(): # lock + update atomically user = await User.query.filter(id=user_id).select_for_update().get() user.language = "EN" await user.save() # skip locked batch async with database.transaction(): users = await ( User.query.filter(active=True).order_by("id").select_for_update(skip_locked=True).limit(50) ) ``` -------------------------------- ### CompositeField Source: https://github.com/dymmond/edgy/blob/main/docs/fields/index.md Documentation for the CompositeField class, including its parameters and usage example. ```APIDOC ## CompositeField ### Description Creates a composite field that groups multiple fields together, allowing read/write access to the referenced fields as a single unit. It can optionally return a pydantic model instead of a dict. ### Parameters - `inner_fields` (sequence, dict, or Edgy Model) - Required - A sequence of external field names and/or (name, Field) tuples, or an Edgy Model, or a dict mapping names to Fields. - `unsafe_json_serialization` (bool) - Optional - Default False. When True, includes CompositeFields without a pydantic model in JSON dumps. - `absorb_existing_fields` (bool) - Optional - Default False. When True, does not fail if fields specified with (name, Field) tuples already exist; treats them as internal fields. - `model` (pydantic model) - Optional - Default None. When set, returns a pydantic model instead of a dict. - `prefix_embedded` (str) - Optional - Default "". Prefixes the field names of embedded fields. - `prefix_column_name` (str) - Optional - Prefixes the `column_name` of sub-fields when defined. ### Usage Example ```python import edgy class MyModel(edgy.Model): email: str = edgy.EmailField(max_length=60, null=True) sent: datetime.datetime = edgy.DateTimeField(null=True) composite: edgy.CompositeField = edgy.CompositeField(inner_fields=["email", "sent"]) obj = MyModel() obj.composite = {"email": "foobar@example.com", "sent": datetime.datetime.now()} # retrieve as dict ddict = obj.composite ``` ``` -------------------------------- ### Simple counting up with increment_on_simulated by the original prompt it's spelled ascii, I'll copy exactly: 'introduce a placeholder to avoid repetition?```json { Source: https://github.com/dymmond/edgy/blob/main/docs/fields/index.md Demonstrates basic usage of `in/Users/.../Desktop/Repos/dymmond-test/docs/ the original prompt it's spelled ascii, I'll copy exactly: 'increment_on_simulated by the original prompt it's spelled ascii, response```json { ```example.com import edghis is a placeholder to avoid repetition? response```json ```json { ``` ```example.com imported from the original prompt it's spelled ascii, response```json ```json { ``` ```example.com imported from the original prompt it's ```json ```json ```json ```json ```json ```json ```json ```.response```json { ``` ```example.com imported from the original prompt it's spelled ascii, response```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```json ```.response```json ```json ```json ```json ``` -------------------------------- ### Create user instances with User.query.create() Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Creates model instances using the create method. It accepts ModelRefs as positional arguments to automatically evaluate and stage them. Callables are not evaluated here because there is no model for reference. ```python await User.query.create(is_active=True, email="foo@bar.com") await User.query.create(is_active=False, email="bar@foo.com") await User.query.create(is_active=True, email="foo@bar.com", first_name="Foo", last_name="Bar") ``` -------------------------------- ### Create a User API with Edgy and Ravyn Source: https://github.com/dymmond/edgy/blob/main/README.md This example demonstrates how to define an Edgy model named User with fields including an integer primary key and various character fields, integrate it with a SQLite database using an in-memory or file-based connection URI, and expose a POST /create endpoint using the Ravyn app.opalindrome.works.works.works.works.works.works. The `create_user handler accepts a User object directly, saves it to the source.works.works. The app-level callbacks ensure the database connection is established before handling requests and closed after. The response of the API is expected to be JSON similar to the one shown in the following snippet. ```python from raven import Raven,ateway,post import edyn from edyn.testclient import DatabaseTestClient as Database database = Database( ``` -------------------------------- ### QuerySet.select Source: https://github.com/dymmond/edgy/blob/main/docs/queries/queries.md Obtains a single record from the database, serving as an alternative to get. ```APIDOC ## QuerySet.select ### Description Obtains a single record from the database, serving as an alternative to get. ### Method GET ### Endpoint User.query.select(...) ### Parameters #### Query Parameters - **kwargs** (dict) - Required - Field-value pairs to filter the record. ### Request Example ```python user = await User.query.select(email="foo@bar.com") ``` ### Response #### Success Response (200) Returns the matching record instance. ### Notes - Can be mixed with queryset returns, e.g., `User.query.filter(email="foo@bar.com").select()`. ``` -------------------------------- ### utils.py with lru_cache for get_db_connection Source: https://github.com/dymmond/edgy/blob/main/docs/tips-and-tricks.md Create a `utils.py` file that applies the `lru_cache` technique to the `db_connection` function. This ensures that calling `get_db_connection()` returns the same connection and registry instance. Do not place this function in the application entry point; use the edgy.monkay.instance sandwich technique instead. ```python {!> ../docs_src/tips/lru.py !} ``` -------------------------------- ### Combine exclude_secrets with other operations Source: https://github.com/dymmond/edgy/blob/main/docs/queries/secrets.md Demonstrates combining `exclude_secrets` with `filter`, `get`, and `only` operations. ```python users = await User.query.filter(id=1).exclude_secrets() users = await User.query.filter(id=1).exclude_secrets().get() # returns only 1 object users = await User.query.exclude_secrets().only("email") ``` -------------------------------- ### SubFactory with Object Import and Parameterization Source: https://github.com/dymmond/edgy/blob/main/docs/testing/model-factory.md Demonstrates using SubFactory with a direct object import and setting parameters on the factory field, including chaining SubFactory in another factory. ```python class UserFactory(ModelFactory): class Meta: model = User name = "John Doe" language = "en" class ProductFactory(ModelFactory): class Meta: model = Product name = "Product 1" rating = 5 in_stock = True user = SubFactory(UserFactory) # Object import user.parameters["randomly_nullify"] = True class ItemFactory(ModelFactory): class Meta: model = Item product = SubFactory(ProductFactory) product.parameters["randomly_nullify"] = True ```