model 0.0.3

  • Readme
  • Changelog
  • Example
  • Installing
  • 64

model #

Create models of database tables.

Getting Started #

In your flutter project add the dependency:

dependencies:
  ...
  model: ^0.0.3

For help to get started with Flutter, view the online documentation.

Usage example #

Import model.dart

import 'package:model/model.dart';

[0.0.3] - 2020/06/13 #

  • example
  • queryTables -> printTables

[0.0.2] - 2020/06/09. #

  • New classes:

    • DBProvider
    • Model
    • MetaModel
    • Table
    • Column
    • Constraint
      • Default
      • Unique
      • NotNull
      • Check
      • References
    • SQLiteType enum
  • Importing whole package with:

import 'package:model/model.dart';

[0.0.1] - 2020/05/28. #

  • Package initialization.

example/main.dart

import 'package:model/model.dart';

// Create models Author and Book by extending Model class.
//

class Author extends Model {
  static const table = 'author';
  static const nameCol = 'name';

  @override
  String get tableName => table;

  String name;

  Author({this.name});

  @override
  Map<String, dynamic> toMapForDB() => {nameCol: name};
}

class Book extends Model {
  static const table = 'book';
  static const titleCol = 'title';
  static const descriptionCol = 'description';
  static const priceCol = 'price';
  static const numberOfPagesCol = 'number_of_pages';
  static const authorIdCol = 'author_id';

  @override
  String get tableName => table;

  String title;
  String description;
  double price;
  int numberOfPages;
  int authorId;

  Book({
    this.title,
    this.description,
    this.price,
    this.numberOfPages,
    this.authorId,
  });

  @override
  Map<String, dynamic> toMapForDB() => {
        titleCol: title,
        descriptionCol: description,
        priceCol: price,
        numberOfPagesCol: numberOfPages,
        authorIdCol: authorId,
      };
}

// Extend DBProvider class to provide database.

class MyDBProvider extends DBProvider {
  @override
  String get databaseName => 'books';

  @override
  int get databaseVersion => 1;

  @override
  Map<String, List<Column>> get tables => {
        Book.table: <Column>[
          Column(Book.titleCol, SQLiteType.text, <Constraint>[
            Unique(),
            NotNull(),
            Default(''),
          ]),
          Column(Book.descriptionCol, SQLiteType.text),
          Column(Book.priceCol, SQLiteType.real),
          Column(Book.numberOfPagesCol, SQLiteType.integer),
          Column(Book.authorIdCol, SQLiteType.integer, <Constraint>[
            References(Author.table),
          ])
        ],
        Author.table: <Column>[
          Column(Author.nameCol, SQLiteType.text, <Constraint>[
            Unique(),
            NotNull(),
          ])
        ],
      };
}

// Main method shows the use of the provider together with the models.

void main() async {
  final dbProvider = await MyDBProvider().open();

  final author = Author(name: 'foo');
  await author.save();

  final book = Book(
    title: 'bar',
    description: 'foo bar',
    price: 10.0,
    authorId: author.id,
  );
  await book.save();

  // Print tables.
  dbProvider.printTables();

  book.delete();

  // Book should no longer exist.
  dbProvider.printTables();
}

Use this package as a library

1. Depend on it

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


dependencies:
  model: ^0.0.3

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:model/model.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
32
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
64
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.14
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform linux

Because:

  • package:model/model.dart that imports:
  • package:model/src/model.dart that imports:
  • package:model/src/db_provider.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform web

Because:

  • package:model/model.dart that imports:
  • package:model/src/model.dart that imports:
  • package:model/src/db_provider.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package does not support Flutter platform windows

Because:

  • package:model/model.dart that imports:
  • package:model/src/model.dart that imports:
  • package:model/src/db_provider.dart that imports:
  • package:sqflite/sqflite.dart that declares support for platforms: android, ios, macos

Package not compatible with SDK dart

Because:

  • model that is a package requiring null.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
path ^1.7.0 1.7.0
sqflite ^1.3.0 1.3.1
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
sqflite_common 1.0.2+1
synchronized 2.2.0+1
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
effective_dart ^1.0.0
flutter_test