Db class

Database annotation for generating a database class with repositories

Example:

@Db(
  entities: [UserEntity, PostEntity],
  migrationVersion: 1,
  generateSql: true,  // Generates SQL file in .dart_tool/dorm/
  config: DbConfig.postgresql(
    host: 'localhost',
    database: 'mydb',
    username: 'user',
    password: 'password',
  ),
)
class AppDatabase {
  // Optional: override config in constructor
  AppDatabase([DatabaseConfig? config]);
}

Constructors

Db({required List<Type> entities, int migrationVersion = 1, DbConfig? config, String? name, bool generateSql = false, DatabaseType? sqlDialect})
const

Properties

config DbConfig?
Database configuration (optional, can be passed to constructor)
final
entities List<Type>
List of entity types to include in the database
final
generateSql bool
Generate SQL file with CREATE TABLE statements
final
hashCode int
The hash code for this object.
no setterinherited
migrationVersion int
Current migration version
final
name String?
Optional database name (defaults to config.database if config provided)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sqlDialect DatabaseType?
Target database type for SQL generation (defaults to config.dbType or postgresql)
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited