flutter_annotation_sqlite

Last updated:

0 purchases

flutter_annotation_sqlite Image
flutter_annotation_sqlite Images
Add to Cart

Description:

flutter annotation sqlite

flutter_annotation_sqlite #
Annotation-based Sqlite library.
Example #

Entity

@Entity(/*table: 'tb_person'*/)
class Person {
@Id()
final int id;

@Column(unique: true)
final String name;
@Column()
final int age;
@Column()
final double height;

@Column(name: 'is_vip', indexable: true)
final bool isVip;

@Column()
final Address? address;

@Column()
final DateTime? birthday;
}
copied to clipboard

Repository

@Repository(Person)
abstract class PersonRepository {
static PersonRepository create(sqflite.Database database) =>
_$PersonRepository(database);

@Query()
Future<List<Person>> findEntities(int page,
{String? likeName, int limit = 20});

@Query()
Future<Person?> findById(int id);

@Query()
Future<Map> findMapByName(String name);

@Query(fields: ['name', 'isVip'])
Future<Map> findValueById(int id);

@Query(fields: ['age'])
Future<int> findAgeByName(String name);

@Query(fields: ['birthday'])
Future<DateTime> findBirthdayByName(String name);

@Query(fields: [
'name'
], orderBy: [
{'age': OrderingTerm.desc},
{'height': OrderingTerm.asc}
])
Future<List<String>> findNames(bool isVip, {double? orGteHeight});

@Query(fields: ['birthday'])
Future<List<DateTime>> findBirthdays(bool isVip);

@Query(
fields: ['id', 'name', 'age', 'height', 'isVip', 'address', 'birthday'])
Future<List<Map<String, dynamic>>> findValues([String? likeName]);

@Insert(sqflite.ConflictAlgorithm.abort)
Future<void> insert(Person entity);

@Update()
Future<void> updateById(Person entity, int id);

@Update(conflict: sqflite.ConflictAlgorithm.replace, ignoreNull: true)
Future<void> updateAll(Person entity);

@Delete()
Future<void> delete(int id);

@Delete()
Future<bool> deleteByAge(int age, {double? orHeight});
}
copied to clipboard


Support operate keyword

like: LIKE cloumn%
or: OR
and: AND
orGt|orGte: OR cloumn > ? | OR cloumn >= ?
orLt|orLte: OR cloumn < ? | OR cloumn <= ?



Database


@Database(
version: 1,
entities: [Person, Address],
migrations: [V2Migrator],
)
abstract class AppDatabase {
sqflite.Database get database;

Future<void> open(String dbPath, {bool inMemory = false});

Future<void> close();

sqflite.DatabaseFactory get sqliteFactory {
if (kReleaseMode) {
return sqflite.databaseFactorySqflitePlugin;
}
// print SQL
return sqlLoggerFactory(sqflite.databaseFactorySqflitePlugin);
}

static AppDatabase create() => _$AppDatabase();
}
copied to clipboard

Migration

class V2Migrator extends Migrator {
@override
FutureOr<void> onMigration(sqflite.Database db) {
// TODO: implement onMigration
throw UnimplementedError();
}

@override
int get fromVersion => 1;

@override
int get toVersion => 2;
}
copied to clipboard

License:

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Files In This Product:

Customer Reviews

There are no reviews.