sqflite_migration 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 88

Build Status codecov

Migrate your mobile sqlite database #

Library to manage sqlite db migrations using sqflite plugin.

Getting Started #

import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';

final initialScript = [
  '''
create table _todo_list (
  id integer primary key autoincrement,
  alias text not null
  )
''',
  '''
create table _task (
  id integer primary key autoincrement,
  description text,
  todo_list_id integer not null,
  CONSTRAINT fk_todo_lists
    FOREIGN KEY (todo_list_id)
    REFERENCES _todo_list(id)
);
'''
];

final migrations = [
  '''
  alter table _task add column done integer default 0;
  '''
];

final config = MigrationConfig(initializationScript: initialScript, migrationScripts: migrations);

Future<Database> open() async {
 final databasesPath = await getDatabasesPath();
 final path = join(databasesPath, 'test.db');
 
 return await openDatabaseWithMigration(path, config);
}

Change Log for sqflite_migration #

A library to enable sqlite db migrations, using sqflite plugin.

v0.1.2 - 2019-08-23

Test #

  • remove deprecated failing tests dfc249c

v0.1.1 - 2019-08-23

Chore #

  • replace deprecated fonts-droid dependency in travis, with fonts-droid-fallback 091605a

Bugs #

  • allow empty scripts array closes #2 5d22773

v0.1.0 - 2019-03-19

Chore #

Docs #

v0.0.2 - 2019-03-04

Chore #

Fixes #

  • Use dart:async imports to make the library backward compatible. 6b4194e

Docs #

  • enhance package description. e6804ba

This CHANGELOG.md was generated with Changelog for Dart

example/example.dart

import 'dart:async';

import 'package:path/path.dart';
import 'package:sqflite/sqflite.dart';
import 'package:sqflite_migration/sqflite_migration.dart';

final initialScript = [
  '''
create table _todo_list (
  id integer primary key autoincrement,
  alias text not null
  )
''',
  '''
create table _task (
  id integer primary key autoincrement,
  description text,
  todo_list_id integer not null,
  CONSTRAINT fk_todo_lists
    FOREIGN KEY (todo_list_id)
    REFERENCES _todo_list(id)
);
'''
];

final migrations = [
  '''
  alter table _task add column done integer default 0;
  '''
];

final config = MigrationConfig(
    initializationScript: initialScript, migrationScripts: migrations);

class DatabaseRepository {
  static Database _database;
  String path;

  Future<Database> get database async {
    if (_database != null) {
      return _database;
    }

    _database = await _open();
    return _database;
  }

  Future<Database> _open() async {
    final databasesPath = await getDatabasesPath();
    final path = join(databasesPath, 'test.db');

    return await openDatabaseWithMigration(path, config);
  }

  Future<Map> findById(int id) async {
    final db = await database;
    List<Map> maps = await db.query('_task',
        columns: ['id', 'description'], where: 'id = ?', whereArgs: [id]);
    if (maps.length > 0) {
      return maps.first;
    }
    return null;
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  sqflite_migration: ^0.1.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:sqflite_migration/sqflite_migration.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
75
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
88
Learn more about scoring.

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

  • Dart: 2.5.1
  • pana: 0.12.21
  • Flutter: 1.9.1+hotfix.4

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.68.0 <3.0.0
flutter 0.0.0
sqflite ^1.0.0 1.1.7+1
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.7
path 1.6.4
sky_engine 0.0.99
synchronized 2.1.0+1
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test
matcher ^0.12.3+1
mockito ^4.0.0