Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Flutter Moor Session PDF By Meet Janani

Flutter Moor Session PDF By Meet Janani

Flutter Moor Session PDF By Meet Janani

F004d4671b75fb420907840c6dfb5a3d?s=128

Meet Janani

June 17, 2021
Tweet

Transcript

  1. MOOR Manage Offline Database - Meet Janani

  2. What is MOOR • Reactive persistence library for Flutter and

    Dart • Built on top of sqlite • Provides Type Safety, Stream Query, Type Safe SQL, • It is Flexible: let’s you write queried in both [SQL & Dart] • It support Filter, Order, Joins on Multiple Tables • Moor Is just Room spelled backward. (Room we are using in Android)
  3. Why MOOR • Provide us APIs in dart as well.

    • Moor provides Tables, queries, migration, IDE for SQL, complex filters. • Moor helps you keep your database code simple and easy to understand. • Identify or catches the error and provides the solution • Moor is fast like FLUTTER. • Moor works on Android, iOS, macOS, Windows, Linux, and the web. • Moor is stable and well tested with a wide range of unit and integration tests. It powers the production of Flutter apps. • Moor also uses Sqlite Packages • Moor itself uses SQL as its backend so in flutter we can directly create a Table using Dart.
  4. • pubspec.yaml Adding The Dependancy? • moor: This is the

    core package defining most apis • sqlite3_flutter_libs: Ships the latest sqlite3 version with your Android or iOS app. • path_provider and path: Used to find a suitable location to store the database. Maintained by the Flutter and Dart team • moor_generator: Generates query code based on your tables • build_runner: Common tool for code-generation, maintained by the Dart team
  5. The Database Class BreakDown:
 
 1) Annotate With UseMoor()
 2)

    it Consume Table Array
 3) DB Name & Log Statement Boolean
 4) SchemaVersion starts with 1
  6. Creating A Table BreakDown:
 
 1) Create Table By Just

    Extending Table
 2) IntColumn & TextColumn is DataType 3) Rest of The Things will handle Build_Runner for Creating Table import 'package:moor_flutter/moor_flutter.dart'; part 'moor_database.g.dart'; class Orders extends Table { TextColumn get price => text()(); IntColumn get id => integer().autoIncrement()(); TextColumn get productName => text()(); } @UseMoor(tables: [Orders]) class AppDatabase{ } @override Set<Column> get primaryKey => {id, productName};
  7. BreakDown:
 
 1) Auto Increment
 2) Min Max Length Validation

    3) set different column name from variable name 4) Allow nullable values
 5) Custom Table/Column name More On Creating Table String get tableName => 'categories'; IntColumn get parentCategory => integer().named('parent')();
  8. Supported Column Types

  9. Queries BreakDown:
 
 1) Select Query Format: select(tableName)
 * Return

    Once with get()
 * Return Live Updates with watch() 
 2) Insert Query Format: into(tableName).insert(Object)
 3) Update Query Format: update(tableName).replace(Object)
 4) Delete Query Format: delete(tableName).delete(Object)
  10. Example of Moor Let’s Explore cup of Moor

  11. Aliases

  12. Migration

  13. Thank you

  14. Reference • Master: https://moor.simonbinder.eu/ • Docs: https://moor.simonbinder.eu/docs/ • Migration: https://moor.simonbinder.eu/docs/advanced-features/migrations/

    • Demo Project: https://medium.com/flutterdevs/moor-database-in-flutter-6a78d91b10e5