Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/p32929/easiestdbflutter

The Easiest and the Laziest approach to Flutter SQL Database.
https://github.com/p32929/easiestdbflutter

flutter flutter-package flutter-plugin flutter-sqflite flutter-sql flutter-sqlite flutterpackage sql sqlite sqlite-database sqlite3

Last synced: 3 months ago
JSON representation

The Easiest and the Laziest approach to Flutter SQL Database.

Awesome Lists containing this project

README

        

![New Project](https://user-images.githubusercontent.com/6418354/87636772-0ce14100-c763-11ea-8d8b-0c7c36ae5ebe.png)

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

How to use
Contribution
License
Support

[![](https://badgen.net/github/watchers/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/stars/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/forks/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/issues/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/open-issues/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/closed-issues/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/label-issues/p32929/EasiestSqlFlutter/help-wanted/open)]() [![](https://badgen.net/github/prs/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/open-prs/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/closed-prs/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/merged-prs/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/commits/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/last-commit/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/branches/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/releases/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/tags/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/license/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/contributors/p32929/EasiestSqlFlutter)]() [![](https://badgen.net/github/dependents-pkg/p32929/EasiestSqlFlutter)]()

[![](https://badgen.net/pub/v/easiestdb)]() [![](https://badgen.net/pub/likes/easiestdb)]() [![](https://badgen.net/pub/sdk-version/easiestdb)]() [![](https://badgen.net/pub/flutter-platform/easiestdb)]()

## Share
Sharing with your friends is just one click away from here

[![facebook](https://image.flaticon.com/icons/png/32/124/124010.png)](https://www.facebook.com/sharer/sharer.php?u=https://pub.dev/packages/easiestdb)
[![twitter](https://image.flaticon.com/icons/png/32/124/124021.png)](https://twitter.com/intent/tweet?source=https://pub.dev/packages/easiestdb)
[![tumblr](https://image.flaticon.com/icons/png/32/124/124012.png)](https://www.tumblr.com/share?v=3&u=https://pub.dev/packages/easiestdb)
[![pocket](https://image.flaticon.com/icons/png/32/732/732238.png)](https://getpocket.com/save?url=https://pub.dev/packages/easiestdb)
[![pinterest](https://image.flaticon.com/icons/png/32/124/124039.png)](https://pinterest.com/pin/create/button/?url=https://pub.dev/packages/easiestdb)
[![reddit](https://image.flaticon.com/icons/png/32/2111/2111589.png)](https://www.reddit.com/submit?url=https://pub.dev/packages/easiestdb)
[![linkedin](https://image.flaticon.com/icons/png/32/1409/1409945.png)](https://www.linkedin.com/shareArticle?mini=true&url=https://pub.dev/packages/easiestdb)
[![whatsapp](https://image.flaticon.com/icons/png/32/733/733585.png)](https://api.whatsapp.com/send?text=https://pub.dev/packages/easiestdb)

## 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](https://pub.dev/packages/easiestdb) 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 init({ String dbName = 'demo.db', int version = 1, List tables })`
###### `DbTable(String tableName, {List 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 addData(int tableIndex, List 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>> 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>> 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>> 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 updateOneDataById(int tableIndex, int rowId, List 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 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 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](https://github.com/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