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

outdated

Dart plugin to retrieve and update data on BagelDB. This library allows you to build a backend in a matter of minutes, make REST API requests and manage your content easily

example/main.dart

// Copyright 2020 Bagel Studio ltd. All rights reserved.
// For an example app, see https://github.com/bagelstudio/bagel_pizza

import 'dart:io';

import '../lib/bagel_db.dart';


// create an instance of BagelDB
BagelDB bagelDB = BagelDB('BearerTestToken'); // replace with your project id

// a var that will hold the response from BagelDB
BagelResponse response = BagelResponse(data: {}, statusCode: 0);

// get data using Builder pattern
void getFromBagelDB() async {
  // simple get request
  await bagelDB.collection('testItems').get();

  // get with query
  await bagelDB.collection('testItems').query('position', '=', 'developer').query('age', '>', '27').get();

  // sort the data by parameter
  await bagelDB.collection('testItems').sort('age').get();

  // sort with order
  await bagelDB.collection('testItems').sort('age', sortOrder: 'asc').get();

  // define how many results will be in each page
  await bagelDB.collection('testItems').perPage(2).get();

  // include all the details for item
  await bagelDB.collection('testItems').everything().get();

  // get a specific item
  await bagelDB.collection('testItems').item('5dr22f010a1466a13e2f967a' /*replace with your item id*/).get();
}

// post item. Post returns the id of item that created
void postToBagelDB() async {
  // post item to BagelDB
  await bagelDB
      .collection('testItems')
      .post(item: {'name': 'Baz', 'age': 25, 'position': 'CTO'} /* replace with your item */);
  
  await bagelDB
      .collection('testItems')
      .item("customId")
      .set(item: {'name': 'Baz', 'age': 25, 'position': 'CTO'} /* Creates an item with an custom id you set :: if the item exists it will just update it*/);
}

// put item
void putInBagelDB() async {
  // post item to BagelDB
  await bagelDB.collection('testItems').item('5dr22f010a1466a13e2f967a').put(item: {
    'name': 'Baz',
    'age': 34,
    'position': 'CEO',
  });
}

void deleteFromBagelDB() async {
  await bagelDB.collection('testItems').item('5dr22f010a1466a13e2f967a').delete();
}

// uploading image
void uploadImage() async {
  File image = File('/Users/userName/Desktop/photo-test.jpeg');
  await bagelDB.collection("users").item("3423432").uploadImage("profilePic", image);
}


void getCollectionSchema() async {
  await bagelDB.schema('testItems').get();
}
10
likes
0
pub points
26%
popularity

Publisher

verified publisherbageldb.com

Dart plugin to retrieve and update data on BagelDB. This library allows you to build a backend in a matter of minutes, make REST API requests and manage your content easily

Homepage

License

unknown (license)

Dependencies

dio, flutter, universal_html

More

Packages that depend on bagel_db