sqlcool 3.2.1 copy "sqlcool: ^3.2.1" to clipboard
sqlcool: ^3.2.1 copied to clipboard

outdated

Easy api for Sqlite with reactivity bingings. Stream of changes, select bloc

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:sqlcool/sqlcool.dart';
import 'pages/select_bloc.dart';
import 'pages/index.dart';
import 'pages/join_query.dart';
import 'pages/upsert.dart';
import 'conf.dart';

void main() {
  /// initialize the database async. We will use the [onReady]
  /// callback later to react to the initialization completed event
  initDb();
  runApp(MyApp());
}

Future<void> initDb() async {
  // define the tables
  DbTable category = DbTable("category")..varchar("name", unique: true);
  DbTable product = DbTable("product")
    ..varchar("name", unique: true)
    ..integer("price")
    ..foreignKey("category", onDelete: OnDelete.cascade)
    ..index("name");
  // prepare the queries
  List<String> populateQueries = <String>[
    'INSERT INTO category(name) VALUES("Category 1")',
    'INSERT INTO category(name) VALUES("Category 2")',
    'INSERT INTO category(name) VALUES("Category 3")',
    'INSERT INTO product(name,price,category) VALUES("Product 1", 50, 1)',
    'INSERT INTO product(name,price,category) VALUES("Product 2", 30, 1)',
    'INSERT INTO product(name,price,category) VALUES("Product 3", 20, 2)'
  ];
  // initialize the database
  String dbpath = "items.sqlite";
  await db
      .init(
          path: dbpath,
          schema: [category, product],
          queries: populateQueries,
          verbose: true)
      .catchError((dynamic e) {
    throw ("Error initializing the database: ${e.message}");
  });
}

final routes = {
  '/': (BuildContext context) => PageIndex(),
  '/select_bloc': (BuildContext context) => PageSelectBloc(),
  '/join': (BuildContext context) => PageJoinQuery(),
  '/upsert': (BuildContext context) => UpsertPage(),
};

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Sqlcool example',
      routes: routes,
    );
  }
}
43
likes
40
pub points
36%
popularity

Publisher

unverified uploader

Easy api for Sqlite with reactivity bingings. Stream of changes, select bloc

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

cupertino_icons, flutter, path_provider, pedantic, sqflite, synchronized

More

Packages that depend on sqlcool