brick_sqlite 0.1.0 copy "brick_sqlite: ^0.1.0" to clipboard
brick_sqlite: ^0.1.0 copied to clipboard

outdated

SQLite connector for Brick, a data persistence library for Flutter

example/example.dart

import 'package:brick_core/core.dart';
import '../lib/sqlite.dart';

/// This class and code is always generated.
/// It is included here as an illustration.
/// Sqlite adapters are generated by domains that utilize the brick_sqlite_generators package,
/// such as brick_offline_first_with_rest_build
class UserAdapter extends SqliteAdapter<User> {
  final tableName = "User";

  final fieldsToSqliteColumns = {
    'primaryKey': {
      'name': '_brick_id',
      'type': int,
      'iterable': false,
      'association': false,
    },
    'name': {
      'name': 'name',
      'type': String,
      'iterable': false,
      'association': false,
    }
  };

  primaryKeyByUniqueColumns(instance, executor) async => null;

  fromSqlite(data, {provider, repository}) async {
    return User(
      name: data['name'],
    );
  }

  toSqlite(instance, {provider, repository}) async {
    return {
      'name': instance.name,
    };
  }
}

/// This value is always generated.
/// It is included here as an illustration.
/// Import it from `lib/app/brick.g.dart` in your application.
final dictionary = SqliteModelDictionary({
  User: UserAdapter(),
});

/// A model is unique to the end implementation (e.g. a Flutter app)
class User extends SqliteModel {
  final String name;

  User({
    this.name,
  });
}

class MyRepository extends SingleProviderRepository<SqliteModel> {
  MyRepository()
      : super(
          SqliteProvider(
            "myApp.sqlite",
            modelDictionary: dictionary,
          ),
        );
}

void main() async {
  final repository = MyRepository();

  final users = await repository.get<User>();
  print(users);
}
4
likes
0
pub points
41%
popularity

Publisher

unverified uploader

SQLite connector for Brick, a data persistence library for Flutter

Homepage
Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

brick_core, brick_sqlite_abstract, logging, meta, path, sqflite, synchronized

More

Packages that depend on brick_sqlite