Share
Embed
Flutter Moor Session PDF By Meet Janani
Flutter Moor Session PDF By Meet Janani
Meet Janani
June 17, 2021
Transcript
14 slides
-
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) -
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. -
• 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 -
The Database Class BreakDown: 1) Annotate With UseMoor() 2)
it Consume Table Array 3) DB Name & Log Statement Boolean 4) SchemaVersion starts with 1 -
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}; -
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')(); -
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) -
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