bagel_db 0.1.0 copy "bagel_db: ^0.1.0" to clipboard
bagel_db: ^0.1.0 copied to clipboard

outdated

Dart plugin to retrieve and update data on BagelDB.

example/example.dart

// Copyright 2020 Bagel Studio ltd. All rights reserved.

import 'package:bagel_db/bagel_db.dart';
import 'package:dio/dio.dart';

// create an instance of BagelDB
BagelDB bagelDB = BagelDB(
    organizationId: 'mkd2tbi23pfo11ei0t0g', // replace with your organization id
    apiKey: 'AIzaSyDfZNuVbEN_73RhORbwo-A2hRMMpKBOZZU', // replace with the api key of your projcet
    projectId: 'brh2tg223akg00ei0ung'); // replace with your project id

// create BagelDB instance, with a specific collection
BagelDBRequest bagelDBRequest = BagelDBRequest(bagelDB: bagelDB, collection: 'testItems' /*specify your collection*/);

// a var that will hold data in a JSON format
var data;

// a var that will hold the response from BagelDB
Response response;

// get data, using Builder pattern
void getFromBagelDB() async {
  // simple get
  response = await bagelDBRequest.get();

  // get with query
  response = await bagelDBRequest.addQuery('position:developer').addQuery('age:>:27').get();

  // sort the data bt parameter
  response = await bagelDBRequest.addSort('age').get();

  // sort with order
  response = await bagelDBRequest.addSort('age').addOrder('desc').get();

  // define the number of results in page
  response = await bagelDBRequest.addResponsesPerPage('2').get();

  // specify if you wanted the nested objects fully
  response = await bagelDBRequest.everything().get();

  // get a specific item
  response = await bagelDBRequest.addDoc('5dr22f010a1296a13e2f967a' /*replace with your item id*/).get();

  data = response.data;
}

// post item. Post returns the id of item that created
void postToBagelDB() async {
  // post item to BagelDB
  response =
      await bagelDBRequest.post(item: {'name': 'Baz', 'age': 25, 'position': 'CTO'} /* replace with your item */);
  data = response.data;
}

// put item
void putInBagelDB() async {
  // post item to BagelDB
  response = await bagelDBRequest.put(item: {
    'name': 'Baz',
    'age': 34,
    'position': 'CEO',
    '_id': '2bb9836502f94e7c9b4afb66' // specify the id of the itemwith your item
  }, itemId: '2bb9836502f94e7c9b4afb66' /* specify again the item id */);
  data = response.data;
}

// delete item
void deleteFromBagelDB() async {
  response = await bagelDBRequest.delete(itemId: '2bb9836502f94e7c9b4afb66');
  data = response.data;
}
10
likes
0
pub points
34%
popularity

Publisher

verified publisherbageldb.com

Dart plugin to retrieve and update data on BagelDB.

Homepage

License

unknown (LICENSE)

Dependencies

dio, flutter, random_string

More

Packages that depend on bagel_db