sqflite_laravel_style_queries 0.0.4 sqflite_laravel_style_queries: ^0.0.4 copied to clipboard
A flutter project to make sqflite easy queries
import 'package:flutter/material.dart';
import 'package:example/models/UserModel.dart';
import 'package:example/models/UserBookModel.dart';
import 'package:sqflite_laravel_style_queries/helper/models/column_types.dart';
import 'package:sqflite_laravel_style_queries/sqflite_laravel_style_queries.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// open database
await SqfliteEasyDb().open();
// create database table example
UserModel()
.addColumn(name: "id", type: ColumnType.integer, isPrimaryKey: true, isAutoIncrement: true)
.addColumn(name: "name", type: ColumnType.text, isNUll: true)
.addColumn(name: "father_name", type: ColumnType.text, isNUll: true)
.execute();
// create database table example
UserBookModel()
.addColumn(name: "id", type: ColumnType.integer, isPrimaryKey: true, isAutoIncrement: true)
.addColumn(name: "user_id", type: ColumnType.integer, isNUll: false)
.addColumn(name: "name", type: ColumnType.text, isNUll: true)
.execute();
// insert records examples
UserModel(name: "hassan 1", fatherName: "Khawaja Muhammad Asghar Saqi").insert();
UserBookModel(userId: 1, name: "zahidaz.com").insert();
UserBookModel(userId: 1, name: "zahidaz.com2").insert();
UserBookModel(userId: 1, name: "zahidaz.com3").insert();
UserModel(name: "hassan 2", fatherName: "Khawaja Muhammad Asghar Saqi").insert();
UserBookModel(userId: 2, name: "zahidaz.com").insert();
UserModel(name: "hassan 3", fatherName: "Khawaja Muhammad Asghar Saqi").insert();
UserBookModel(userId: 3, name: "zahidaz.com").insert();
// get records example
print("get all records");
print(await UserBookModel().get());
// update record example
UserBookModel(name: "abc").where(UserBookModel().id, 1).update();
print("get all records after update");
print(await UserBookModel().get());
// delete all records example
UserBookModel().where(UserBookModel().id, 1).delete();
print("get all records after delete one");
print(await UserBookModel().get());
// delete all records example
UserBookModel().delete();
print("no record after delete all");
print(await UserBookModel().get());
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Sqlflite Laravel Style',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.green),
useMaterial3: false,
),
home: const MyHomePage(title: 'Example of package'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key, required this.title});
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Container(
width: MediaQuery.of(context).size.width,
child: const Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Text("Example of package"),
Text("Hassan Mehmood"),
Text("https://zahidaz.com"),
],
),
),
);
}
}