Skip to content

feat(orm): add Model.insert() classmethod for bulk inserts#131

Merged
bedus-creation merged 7 commits into
mainfrom
feature/model-bulk-insert
Jun 19, 2026
Merged

feat(orm): add Model.insert() classmethod for bulk inserts#131
bedus-creation merged 7 commits into
mainfrom
feature/model-bulk-insert

Conversation

@bedus-creation

Copy link
Copy Markdown
Contributor

Summary

Adds an async Model.insert() classmethod to the Masonite ORM for bulk-inserting one or many rows without instantiating model instances.

# Single row
await User.insert({"email": "picard@example.com", "votes": 0})

# Multiple rows (bulk)
await User.insert([
    {"email": "picard@example.com", "votes": 0},
    {"email": "janeway@example.com", "votes": 0},
])

Unlike create, insert does not fire model events, apply timestamps, or return model instances. It is intended for high-volume seed and batch operations. The classmethod delegates to the existing query builder insert(), which already supports a single dict or a list of dicts.

Changes

  • masoniteorm/models/model.py: new insert() classmethod
  • tests/.../test_sqlite_builder_insert.py: tests for single-row and bulk classmethod inserts

Testing

uv run pytest tests/masoniteorm/sqlite/builder/test_sqlite_builder_insert.py -v — 6 passed.

Note

Documentation for this feature lives in the separate docs-site repo and is delivered as its own PR.

Add an async insert() classmethod that delegates to the query builder,
supporting a single dict or a list of dicts. Unlike create(), it does
not fire model events, apply timestamps, or instantiate models, making
it suitable for high-volume seed and batch operations.

Includes tests covering single-row and bulk classmethod inserts.
Cover single-row and bulk insert via the new insert() classmethod
against the postgres integration test suite.
@bedus-creation

Copy link
Copy Markdown
Contributor Author

Code review: APPROVED (formal GitHub approval blocked — shared author identity)

Correctness: insert() cleanly delegates to cls.query().insert(values); the builder's insert(values: dict | list) -> int | None handles single dict (wrapped to one-item batch), list of dicts, and returns None on empty input. The classmethod's explicit dict | list -> int | None signature matches the builder exactly.
Patterns: Consistent with existing create/first_or_create/update_or_create classmethods. Async correct.
Tests: 6/6 sqlite builder tests pass locally; postgres tests collect cleanly (live-DB gated). New behavior covered. No blockers — ready to merge.

@bedus-creation bedus-creation merged commit 57eb355 into main Jun 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant