moor 1.1.1

  • Example
  • Installing
  • Versions
  • new62

moor #

This library defines the APIs for the moor persistence library. When using the library, you'll probably want to use the moor_flutter implementation directly.

Please see the homepage of moor for details.

1.1.0 #

  • Transactions

1.0.0 #

  • Initial version of the Moor library


import 'package:moor/moor.dart';

part 'example.g.dart';

// Define tables that can model a database of recipes.

class Categories extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get description => text().nullable()();

class Recipes extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get title => text().withLength(max: 16)();
  TextColumn get instructions => text()();
  IntColumn get category => integer().nullable()();

class Ingredients extends Table {
  IntColumn get id => integer().autoIncrement()();
  TextColumn get name => text()();
  IntColumn get caloriesPer100g => integer().named('calories')();

class IngredientInRecipes extends Table {
  String get tableName => 'recipe_ingredients';

  // We can also specify custom primary keys
  Set<Column> get primaryKey => {recipe, ingredient};

  IntColumn get recipe => integer()();
  IntColumn get ingredient => integer()();

  IntColumn get amountInGrams => integer().named('amount')();

@UseMoor(tables: [Categories, Recipes, Ingredients, IngredientInRecipes])
class Database extends _$Database {
  Database(QueryExecutor e) : super(e);

  int get schemaVersion => 1;

  MigrationStrategy get migration => MigrationStrategy(onFinished: () async {
        // populate data
        await into(categories).insert(Category(description: 'Sweets'));

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  moor: ^1.1.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter packages get

Alternatively, your editor might support pub get or flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:moor/moor.dart';
Version Uploaded Documentation Archive
1.1.1 Mar 10, 2019 Go to the documentation of moor 1.1.1 Download moor 1.1.1 archive
1.1.0 Mar 10, 2019 Go to the documentation of moor 1.1.0 Download moor 1.1.0 archive
1.0.0 Mar 9, 2019 Go to the documentation of moor 1.0.0 Download moor 1.0.0 archive
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Mar 10, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14


Detected platforms: Flutter, web, other

No platform restriction found in primary library package:moor/moor.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.2-dev.0.0 <3.0.0
meta >=1.0.0 <2.0.0 1.1.7
Dev dependencies
build_runner ^1.2.0
build_test ^0.10.6
mockito ^4.0.0
moor_generator ^1.1.1
test ^1.5.3
test_api any