quds_db_interface 0.0.5
quds_db_interface: ^0.0.5 copied to clipboard
A unified SQL database interface package that simplifies creating databases and tables, CRUD operations, and queries with modelization across various SQL engines.
Quds DB Interface #
A highly modular, engine-agnostic database abstraction layer for Dart and Flutter applications.
quds_db_interface provides the foundational blueprint for building pure-Dart architectures. It defines strongly-typed properties, strict query-builders, and automated table providers without tightly coupling your application to any specific database engine (such as SQLite, MySQL, or PostgreSQL).
Core Architecture #
The architecture is divided into four core pillars, designed to provide maximum type safety and minimal boilerplate.
- DbModel: Represents a database table row. Models are defined by pure-Dart
FieldDefinitionproperties (StringField,IntField,BoolField,JsonField, etc.), ensuring strict typing across the entire database layer. - TableProvider: The engine responsible for all CRUD operations and bulk transactions. It accepts strict closures (
Condition Function(T model)) to guarantee compile-time type safety over database reads, writes, and filtering logic. - QueryBuilder: Provides complex, multi-table relationship capabilities (such as
INNER JOINandLEFT JOIN) and aggregations (GROUP BY,HAVING,MAX,COUNT). - DatabaseAdapter & DatabaseConnection: The lowest-level wrapper that manages execution and handles transactions natively via a zone-based execution context (
transaction(() async { ... })). - Migrations: Versioned, Dart-first schema evolution through
connection.migrations(Migration,MigrationContext,SchemaMigrationRunner). Prefer typed helpers such ascreateTable/addColumn/updateRows; userawSqlonly when an engine-specific edge case cannot be expressed in Dart.
Key Concepts and Recent Updates #
Silent Bulk Operations #
The interface inherently supports optimized bulk processing. Methods like insertCollection are designed to suppress individual entry listeners during bulk operations. Instead of triggering a UI rebuild for every inserted row, implementing packages notify listeners exactly once via EntryChangeType.collectionInsertion when the bulk transaction has been safely and atomically committed.
Zone-Based Transactions #
The interface standardizes the concept of Zone-based transactions. By wrapping logic in connection.transaction(), implementers can provide a seamless transaction context to all underlying providers, removing the need to manually pass a transaction object throughout the application architecture.
Building an Implementer #
If you intend to implement this interface for a specific engine (e.g., PostgreSQL or SQLite), you must satisfy the following components:
- Adapter implementation: Implement
DatabaseAdapterto handle database initialization, connection pooling, and configuration settings. - Connection implementation: Implement
DatabaseConnectionto routerawQuery,rawExecute, andtransactionblocks to the native engine SDK. - Provider implementation: Extend
TableProvider<T>orStandardTableProvider<T>. This class must orchestrate the translation of the abstract objects provided byquds_db_interface(such asCondition,DataPageQuery, andQueryBuilder) into the engine's specific SQL dialect or query syntax.
For a complete, production-ready implementation of this interface, please refer to the quds_db_sqlite package.