docdb 0.0.2 copy "docdb: ^0.0.2" to clipboard
docdb: ^0.0.2 copied to clipboard

outdated

A SQLite-based document store for Flutter.

DocDB #

DocDB is a simple document database for Flutter that stores document metadata in one table and key-value pairs in separate tables for each data type. It is not an ORM for SQLite.

Installation #

Add docdb as a dependency in your pubspec.yaml file:

dependencies:
  docdb:

Then run flutter pub get to install the package.

Usage #

Connecting to the database Before you can use DocDB, you need to connect to a database. You can use the connect method to do this:

import 'package:docdb/docdb.dart';

final db = DocDB();
await db.connect(dbName: 'mydb.db');

The connect method creates the database file if it doesn't exist and opens a connection to the database.

Storing documents #

To store a document, create a Doc object and add fields to it:

final doc = Doc();
doc['title'] = 'My Document';
doc['content'] = 'Lorem ipsum dolor sit amet...';
await db.insert(doc);

The insert method adds the document to the database and returns the document ID.

Retrieving documents #

To retrieve a document, use the get method:

final docId = 1; // ID of the document to retrieve
final doc = await db.get(docId);
print(doc['title']); // Prints the title of the document

The get method returns a Doc object with the specified ID.

Updating documents #

To update a document, retrieve it using the get method, modify its fields, and then call the update method:

final docId = 1; // ID of the document to update
final doc = await db.get(docId);
doc['title'] = 'New Title';
await db.update(doc);

The update method saves the changes to the database.

Deleting documents #

To delete a document, use the delete method:

final docId = 1; // ID of the document to delete
await db.delete(docId);

The delete method removes the document and its associated key-value pairs from the database.

Filtering documents #

You can filter documents by a specific field value using the filter method:

final docs = await db.filter('title', 'My Document');
print(docs.length); // Prints the number of documents with the specified title

The filter method returns a list of Doc objects that match the specified criteria.

License #

DocDB is released under the MIT License. See LICENSE for details.

2
likes
0
points
30
downloads

Publisher

unverified uploader

Weekly Downloads

A SQLite-based document store for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, path, sqflite, sqflite_common_ffi

More

Packages that depend on docdb