FlexDB is a flexible, free-to-use database service that allows for instant and seamless integration through its REST API. This library, flexdb
, provides an easy-to-use wrapper around the FlexDB REST API.
To start using FlexDB in your project, simply run the following command:
npm install flexdb
First, let's import the FlexDB
class from the flexdb
package:
import { FlexDB } from 'flexdb'
Now, create a new instance of the FlexDB
class.
const flexdb = new FlexDB()
You can pass an optional configuration object containing your API key and the API endpoint:
const flexdb = new FlexDB({ apiKey: 'your_api_key' })
A store is like a container for your data. To create a new store, call the createStore
method with a unique name:
const store = await flexdb.createStore('my-store')
To fetch an existing store by its name (when using an API key), use the getStore
method:
const store = await flexdb.getStore('my-store')
If you want to make sure a store exists before performing any operations, use the ensureStoreExists
method. It will return the existing store or create a new one if it doesn't exist:
const store = await flexdb.ensureStoreExists('my-store')
A collection is a group of related documents within a store. To create a new collection, call the collection
method on a store instance:
const collection = store.collection('my-collection')
To add a new document to a collection, use the create
method and pass an object containing the data you want to store:
const document = await collection.create({ key: 'value' })
To fetch a document by its ID, use the get
method:
const document = await collection.get('document_id')
To update an existing document, call the update
method with the document ID and an object containing the updated data:
const updatedDocument = await collection.update('document_id', { key: 'new_value' })
To remove a document from a collection, use the delete
method and pass the document ID:
await collection.delete('document_id')
To fetch multiple documents from a collection, use the getMany
method. You can pass an options object to control pagination and the number of documents to fetch:
const documents = await collection.getMany({ page: 1, limit: 10 })
To remove an entire collection and all its documents, call the deleteCollection
method:
await collection.deleteCollection()
To delete a store and all its collections, use the delete
method on a store instance:
await store.delete()
This project is licensed under the GPL-3.0 License - see the LICENSE.md file for details.