reactive_sqldb 1.0.6
reactive_sqldb: ^1.0.6 copied to clipboard
reactive_sqldb is a powerful SQLite manager
import 'package:flutter/material.dart';
import 'package:reactive_sqldb/column_def.dart';
import 'dart:async';
import 'package:reactive_sqldb/fields.dart';
import 'package:reactive_sqldb/reactive_sqldb.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({super.key});
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
String _name = 'Unknown';
final _reactiveSqldbPlugin = ReactiveSqldb(name: "mytesting.db");
@override
void initState() {
super.initState();
creteTables();
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> creteTables() async {
///Create Tables
await _reactiveSqldbPlugin.createTable(
"users",
fields: {
"name": ColumnDef(type: FieldType.TEXT, defaultValue: 'asfd'),
"email": ColumnDef(type: FieldType.TEXT, defaultValue: 'sdfasf'),
"gennder": ColumnDef(type: FieldType.TEXT),
},
status: (status, tableName) {},
);
///Listen Tables
_reactiveSqldbPlugin.watchTable("users").listen((rows) {
print('Rows: $rows');
});
///Insert Data
await _reactiveSqldbPlugin.insert("user", {
"name": "David",
"email": "[email protected]",
"gennder": "Male",
});
///Update by id Data
await _reactiveSqldbPlugin.update("user", 2, {
"name": "David 1",
"email": "[email protected]",
});
//Delete by id
await _reactiveSqldbPlugin.delete("user", id: 2);
await _reactiveSqldbPlugin.updateQuery(
'user',
{'name': "Updated", "email": "[email protected]"},
{'id': 2},
);
//Get All item
var userAll = await _reactiveSqldbPlugin.getAll(
"user",
{},
offset: 0,
limit: 20,
);
final rows = await _reactiveSqldbPlugin.getAll('user', {
'deleted_at': ['!=', null],
});
//Query All
var userAllQuery = await _reactiveSqldbPlugin.query(
"user",
where: 'name = ? AND email = ?',
args: ["David", '[email protected]'],
offset: 0,
limit: 10,
);
///Get one item
var user = await _reactiveSqldbPlugin.get("user", {"id": 2});
final row = await _reactiveSqldbPlugin.get('user', {
'deleted_at': ['!=', null],
});
final one = await _reactiveSqldbPlugin.get('transactions', {
'type': ['=', 'expense'],
'amount': ['>=', 100],
'deleted_at': ['=', null],
});
///State Change
setState(() {
_name = user != null ? user["name"].toString() : "";
});
print("User get: $user");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('Plugin example app')),
body: Center(child: Text('Running on: $_name\n')),
),
);
}
}