EasiestSqlFlutter - The Easiest and the Laziest approach to Flutter SQL Database.

Overview

New Project

The Easiest and the Laziest approach to Flutter SQL Database for Flutter.

How to useContributionLicenseSupport

Share

Sharing with your friends is just one click away from here

facebook twitter tumblr pocket pinterest reddit linkedin whatsapp

Support

If you like my works and want to support me/my works, feel free to support or donate. My payment details can be found here: https://p32929.github.io/SendMoney2Me/

Installation

check out the pub.dev for updated installation instructions

Basic Usage

Init using Database name, Table names and Column names. After that, you can do all kinds of CRUD ( Create, Read, Update, Delete ) operations.

Add as many tables and columns you want using these simple codes.

Initialize the Database and the Tables

static Future<Database> init({ String dbName = 'demo.db', int version = 1, List<DbTable> tables })
DbTable(String tableName, {List<DbColumn> dbColumns})
DbColumn(String columnName, {String columnDataType = " TEXT "})

Suppose, we're trying to create a database of two tables named People and Test, each containing three columns. So, we'll write:

EasiestDb.init(dbName: "Data", version: 1, dbTables: [
    DbTable("People", dbColumns: [
      DbColumn('Col 1'), // Default data type is TEXT
      DbColumn('Col 2'),
    ]),
    DbTable("Test", dbColumns: [
      DbColumn('Col 3'),
      DbColumn('Col 4', columnDataType: "TEXT UNIQUE"),
    ]),
  ]);

Look carefully, we didn't add any ID primary key column. That's because easiestdb library does it by default for each table.

Also, you may add as many SQL Constrains in columnDataType parameter. By default, its set to TEXT.

Add data

static Future<int> addData(int tableIndex, List<Datum> data)
Datum(int columnIndex, String value)

Add data in the 1st(0) table:

EasiestDb.addData(0, [
    Datum(1, "AAA"),
    Datum(2, "123"),
]).then((id) {
    print("ID: $id");
});

To pass anything other than string in addData function, you can just convert them to String and pass it ( may be by using yourValue.toString() )

Get All data from a table

static Future<List<Map<String, dynamic>>> getAllData(int tableIndex, {bool ascending = true})

Get all data from the 1st(0) table ( all the indexes start from 0 )

EasiestDb.getAllData(0).then((listMap) {
    listMap.forEach((map) {
        print("${map.values.elementAt(0)}"); // Showing the value of the ID column
        print("${map.values.elementAt(1)}"); // Showing the value from another column
    });
});

Get one data

static Future<List<Map<String, dynamic>>> getOneRowData(int tableIndex, int rowId)

Get data from the 1st(0) table and the 7th(7) row ( all the indexes start from 0 but the rowId starts from 1 )

EasiestDb.getOneRowData(0, 7).then((listMap) {
    listMap.forEach((map) {
        print("${map.values.elementAt(0)}"); // Showing the value of the ID column
        print("${map.values.elementAt(1)}"); // Showing the value from another column
    });
});

Search data

static Future<List<Map<String, dynamic>>> getRowsByMatchingColumnData(int tableIndex, int columnIndex, var valueToMatch, {bool ascending = true})

Searching data in 1st(0) table in the 2nd(1) column by a value:

EasiestDb.getRowsByMatchingColumnData(0, 1, 'AAA').then((listMap) {
    listMap.forEach((map) {
        print("${map.values.elementAt(0)}"); // Showing the value of the ID column
        print("${map.values.elementAt(1)}"); // Showing the value from another column
    });
});

Update data in a row

static Future<int> updateOneDataById(int tableIndex, int rowId, List<Datum> data)
Datum(int columnIndex, String value)

Update data in the first table (0), 7th(7) row:

EasiestDb.updateOneDataById(0, 7, [
    Datum(1, "F F F F F F "),
    Datum(2, "G G G G G G "),
]).then((count) {
    print("Count: $count");
});

Delete one row data

static Future<int> deleteOneData(int tableIndex, int rowId)

Delete the 7th(7) row from the 1st(0) table:

EasiestDb.deleteOneData(0, 7).then((val) {
    print("Count: $val");
});

Delete a row if value matches in a column

static Future<int> deleteDataBySearchingInColumn(int tableIndex, Datum datum)
Datum(int columnIndex, String value)

Delete a one/more data from the first table if matches value in the 2nd(1) column:

EasiestDb.deleteDataBySearchingInColumn(0, Datum(
    1, "F F F F F F "
)).then((val) {
    print("Count: $val");
});

Delete all data from a table

static void deleteTable(int tableIndex)

Delete/Drop the 2nd(1) table:

EasiestDb.deleteTable(1);

Delete the all data from the database

static void deleteDatabase()

Delete/Drop the whole database:

EasiestDb.deleteDatabase();

Run custom SQL commands

static Database getDatabaseObject()

And last but not the least, if you're trying to do something but there's no a function/method created for that command, you can always get the database object and run any custom command like below:

EasiestDb.getDatabaseObject().execute(sqlCommand)

But if you really want that function implemented in easiestdb library, you can:

  1. fork the repo
  2. create a new branch by your github username
  3. add the code
  4. commit + push
  5. make a pull request.

You're welcome...

License

MIT License

Copyright (c) 2020 Fayaz Bin Salam

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Contribution

Lastly, I wanna thank the Flutter team for the amazing framework and tekartik for the sqflite library. And thanks to everyone for using easiestdb and thanks in advance to everyone for contributing...

Also, you might wanna try the Android/Java version of this library from here: https://github.com/p32929/EasiestSqlLibrary

You might also like...

The easiest way to style custom text snippets in flutter

The easiest way to style custom text snippets in flutter

Super Rich Text Check it out at Pub.Dev The easiest way to style custom text snippets Help Maintenance I've been maintaining quite many repos these da

Nov 4, 2022

This library provides the easiest way to integrate Twitter Cards in Flutter web apps 🐦

This library provides the easiest way to integrate Twitter Cards in Flutter web apps 🐦

The Easiest Way to Integrate Twitter Cards into Your Flutter Web App 🐦 1. Guide 🌎 1.1. Features 💎 1.2. Getting Started ⚡ 1.2.1. Install Library 1.2

Aug 7, 2022

The easiest way to create your animated splash screen in a fully customizable way.

The easiest way to create your animated splash screen in a fully customizable way.

Animated Splash Screen Check it out at Pub.Dev Do it your way Assets image Custom Widget Url image IconData Or just change PageTransition and/or Splas

Nov 10, 2022

Use the easiest way to create a dotted line view 👀!

Use the easiest way to create a dotted line view 👀!

fdottedline Use the easiest way to create a dotted line view 👀 ! [FDottedLine] provides developers with the ability to create dashed lines. It also s

Jul 17, 2022

A Note app built with flutter and integrate with Firebase for user authentication and backend database.

A Note app built with flutter and integrate with Firebase for user authentication and backend database.

Note App Note app (Both frontend and backend) created with Flutter and Firebase. Complete UI Contains Sign in & Sign up Home Screen Setting screen Acc

Dec 4, 2022

simple note application using Flutter ,Dart and SQLite database

note_app A new Flutter project. Getting Started This project is a starting point for a Flutter application. A few resources to get you started if this

Feb 15, 2022

A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage

A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage

A working Twitter clone written in Flutter using Firebase auth,realtime,firestore database and storage

Dec 24, 2022

A working Twitter clone built in Flutter using Firebase auth,realtime,firestore database and storage.

A working Twitter clone built in Flutter using Firebase auth,realtime,firestore database and storage.

Fwitter - Twitter clone in flutter A working Twitter clone built in Flutter using Firebase auth,realtime,firestore database and storage. Dependencies

Oct 5, 2022

Lightweight and blazing fast key-value database written in pure Dart.

Lightweight and blazing fast key-value database written in pure Dart.

Fast, Enjoyable & Secure NoSQL Database Hive is a lightweight and blazing fast key-value database written in pure Dart. Inspired by Bitcask. Documenta

Dec 30, 2022
Owner
Fayaz Bin Salam
CEO at RichIT
Fayaz Bin Salam
Flutter App Templete is a project that introduces an approach to architecture and project structure for developing Flutter apps.

Flutter App Template "Flutter App Template" is a project that introduces an approach to architecture and project structure for developing Flutter apps

Altive 126 Jan 5, 2023
Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to tidily bound separated logic into complex solution.

Flutter Control is complex library to maintain App and State management. Library merges multiple functionality under one hood. This approach helps to

Roman Hornak 23 Feb 23, 2022
Yet another localization approach in Flutter

Flutter Global Summit Vol.2 schedule Source code of the mobile application that displays the schedule of the Flutter Global Summit Vol.2 conference th

Anna Leushchenko 3 Mar 24, 2022
Clean Architecture Project with TDD Approach

Clean-Architecture-Project-with-TDD-Approach Small project to implement TDD(Testing Driven Development) by applying SOLID and YAGNI and rules(Clean Ar

null 7 Jun 24, 2022
Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file folder.

Flutter UI Boilerplate "Sharing for fun" Flutter ui boilerplate is easiest way to create new flutter project with clean code and well organized file f

Dimas Ibnu Malik 122 Dec 1, 2022
Easiest way to add support for light and dark theme in your flutter app.

Adaptive Theme Easiest way to add support for light and dark theme in your Flutter app. It allows to manually set light or dark theme and also lets yo

Birju Vachhani 287 Dec 27, 2022
Flutter The lightest, easiest and most convenient route management!

Language: English | 中文简体 nav_router nav_router is the simplest / lightweight / convenient routing management solution for flutter. It supports various

FlutterCandies 104 Jan 3, 2023
This library provides the optimized and easiest way to authenticate with Mastodon's OAuth 2.0 in your Flutter app 🎯

The Optimized and Easiest Way to Integrate OAuth 2.0 with Mastodon API in Flutter ?? 1. Guide ?? 1.1. Getting Started ⚡ 1.1.1. Install Library 1.1.2.

Mastodon.dart 11 Jul 7, 2023
This library provides the easiest and powerful Dart/Flutter library for Mastodon API 🎯

The Easiest and Powerful Dart/Flutter Library for Mastodon API ?? 1. Guide ?? 1.1. Features ?? 1.2. Getting Started ⚡ 1.2.1. Install Library 1.2.2. Im

Mastodon.dart 55 Jul 27, 2023
The easiest way to use navigation, context less and useful methods.

Starlight Utils The easiest way to use navigation, context less and useful methods. Features Name Status Context Less Navigation Service ✅ Context Les

Ye Myo Aung 5 Jul 10, 2022