Item class abstract

数据库操作基类

提供基础的CRUD(创建、读取、更新、删除)操作

使用示例:

// 定义一个User类继承Item
class User extends Item {
  final String name;
  final int age;
  
  User({int? id, required this.name, required this.age}) : super(id: id);
  
  @override
  User copyWith({int? id}) {
    return User(id: id ?? this.id, name: name, age: age); 
  }
}

// 实现UserDao类
class UserDao with CrudMixin<User> {
  @override
  String get tableName => 'users';

  @override 
  User fromMap(Map<String, dynamic> map) {
    return User(
      id: map['id'],
      name: map['name'],
      age: map['age']
    );
  }

  @override
  Map<String, dynamic> toMap(User user) {
    return {
      'name': user.name,
      'age': user.age
    };
  }
}

// 使用示例
void main() async {
  final dao = UserDao();
  await dao.initDb();

  // 创建用户
  final user = User(name: 'John', age: 25);
  final savedUser = await dao.create(user);

  // 读取用户
  final readUser = await dao.read(savedUser.id!);
Implementers

Constructors

Item({int? id})

Properties

hashCode int
The hash code for this object.
no setterinherited
id int?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

copyWith({int? id}) → dynamic
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