Entity class
Annotation for create table in database.
You can set tableName and indices for this table, in this annotation.
If you don't set tableName, the class name will be set as the default name.
You have to set primary key for table using PrimaryKey annotation.
The entity must have exactly one primary key and only integer primary key
can be auto increment.
All properties of the class that this annotation applied on, map to
a column in the table unless properties that Ignore annotation
are applied on. Default column name is property name. If you want to
change it use Column annotation and set name
property.
Also you can set default value for columns using defaultValue
property
of Column annotation.
You can define foreign keys using foreignKeys property of this annotation.
Each item of foreignKeys property is a ForeignKey instance.
@Entity(
tableName: 'notes',
indices: [
Index(columns: ['text'], unique: true)
],
foreignKeys: [
ForeignKey(
entity: User,
parentColumns: ['id'],
childColumns: ['userId'],
onDelete: ForeignKeyAction.CASCADE,
onUpdate: ForeignKeyAction.CASCADE,
deferred: false,
)
],
)
class Note {
@PrimaryKey(autoGenerate: true)
final int? id;
final String text;
final bool isEdited;
final DateTime createDate;
final DateTime? updateDate;
@Column(name: 'lat')
final double? latitude;
@Column(name: 'lng')
final double? longitude;
@Ignore()
final String? ignoreTest;
@Column(name: 'defaultValueTest1', defaultValue: 'test')
final String? defaultValueTest1;
@Column(name: 'defaultValueTest2', defaultValue: '0')
final int? defaultValueTest2;
final int userId;
Note({
this.id,
required this.text,
required this.isEdited,
required this.createDate,
this.updateDate,
this.latitude,
this.longitude,
this.ignoreTest,
this.defaultValueTest1,
this.defaultValueTest2,
required this.userId,
});
}
Properties
-
foreignKeys
→ List<
ForeignKey> ? -
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
indices
→ List<
Index> ? -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tableName → String?
-
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
Static Properties
- fields ↔ _EntityFields
-
getter/setter pair