sqflite_migration 0.1.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 83

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.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.0

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';
  
Version Uploaded Documentation Archive
0.1.0 Mar 19, 2019 Go to the documentation of sqflite_migration 0.1.0 Download sqflite_migration 0.1.0 archive
0.0.2 Mar 4, 2019 Go to the documentation of sqflite_migration 0.0.2 Download sqflite_migration 0.0.2 archive
0.0.1 Mar 3, 2019 Go to the documentation of sqflite_migration 0.0.1 Download sqflite_migration 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
95
Overall:
Weighted score of the above. [more]
83
Learn more about scoring.

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

  • Dart: 2.3.2
  • pana: 0.12.18
  • Flutter: 1.5.4-hotfix.2

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Maintenance issues and suggestions

Support latest dependencies. (-5 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency.

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.6+1
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
path 1.6.2
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