4 Best Flutter ORM and Database Packages

Following are the best ORM frameworks for Flutter.

sqfentity

QFEntity is an ORM framework for CRUD operations and JSON data synchronization to your local SQLite database from the web.

//Create table
const tableStudent = SqfEntityTable(
  tableName: 'category',
  primaryKeyName: 'id',
  primaryKeyType: PrimaryKeyType.integer_auto_incremental,
  useSoftDeleting: true,
  modelName: null,
  fields: [
    SqfEntityField('name', DbType.text),
    SqfEntityField('isActive', DbType.bool, defaultValue: true),
  ]
);
//query data
final students = await Student().select().toList();
Student student = await Student().getById(10);
//save data 
final lastID = await Student(name: "John", isActive: true).save();

jaguar_orm

Jaguar ORM is a source-generated ORM with relations , preloading, cascading, polymorphic relations, composite primary keys, and composite foreign keys.

class Account {
  @PrimaryKey()
  String id;

  String name;

  static const String tableName = '_account';

  String toString() => "Account($id, $name)";
}
@GenBean()
class AccountBean extends Bean<Account> with _AccountBean {
  AccountBean(Adapter adapter) : super(adapter);
}

postgrest

This is a PostgREST client for Dart. The aim is to make an “ORM-like” restful interface.

var url = 'https://example.com/postgrest/endpoint';
var client = PostgrestClient(url);

//read data
var response = await client.from('accounts').select().execute();
//update data
var response = await client.from('accounts').update({ 'status': 'inactive' }).eq('username', 'john').execute();
//delete data
var response = await client.from('accounts').delete().eq('username', 'johnfake').execute();

sqlbrite

This is a reactive stream wrapper around sqflite for Flutter.

//connect to database
final Database db = await openDb();
final briteDb = BriteDatabase(db);

//entity
class Account {
  factory Account.fromJson(Map<String, dynamic> map) { ... }
  
  factory Account.default() { ... }

  Map<String, dynamic> toJson() { ... }
}

// query
final Stream<List<Entity>> listQuery$ = briteDb.createQuery(
  'account',
  where: 'name LIKE ?',
  whereArgs: [queryName],
).mapToList((row) => Account.fromJson(row));

Leave a Comment

Your email address will not be published. Required fields are marked *

By continuing to use the site, you agree to the use of cookies. more information

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.

Close