A Nitrite Database wrapper for Flutter apps using nitrite-database library.
- import
flutter_nitrite
import 'package:flutter_nitrite/flutter_nitrite.dart';
- Then call the
openDatabase
method and pass in your database file as a string.
FlutterNitrite.openDatabase("test.db");
Map user = {
"name": "Olalekan Oladipupo",
"website": "https://github.com/lakexyde"
};
Map response = await FlutterNitrite.createDocument("users", user);
It takes a Collection
name as the first argument and a document as the second. Then returns the saved Document
. If the Collection
doesn't exist, it creates it.
Map response = FlutterNitrite.update("collectionName", doc);
You can also pass in an optional name parameter upsert: true
if you want the document to be inserted if it doesn't exist.
String result = await FlutterNitrite.deleteDocument("CollectionName", 287497989079);
Takes a Collection
name and the _id
of the document. Returns a string message for the transaction.
List response = await FlutterNitrite.find("collectionName");
- it also takes optional named parameters:
offset; // defaults to 0 limit; // defaults to 15
Map response = await FlutterNitrite.findById("collectionName", 235897485085);
It return the Document
or null if it doesn't exist.
- Every created
Document
autogenerates a_id
field in the database for indexing.
List response = await FlutterNitrite.findWhere("collectionName", "field", "value");
It returns a list documents that satisfy the given query. Also takes optional name parameters for offset
and limit
. Good for pagination.