React
3. DB
Overview
There’s 5 functions you can use to interact with the database.
They are used in conjection with the db
property from the useBasic()
hook, and are appended in the format of db.collection('tablename').FUNCTION()
.
.get
.get('ID_OF_ITEM')
Fetch a single item from the table. Returns a promise, or can be used with useQuery
to “subscribe” to data changes
.getAll()
.getAll()
Fetch all items from the table. Returns a promise, or can be used with useQuery
to “subscribe” to data changes
.add()
.add({ 'item': 'value' })
Adds a new item to the table, returns a promise with the new item
.update()
.update({ 'id': 'ID_OF_ITEM', 'value': { 'item': 'value' } })
Updates an item in the table, returns a promise with the updated item
.delete()
.delete('ID_OF_ITEM')
Deletes an item from the table, returns a promise
Examples
Read items
There’s 2 ways to read items from the database:
.get('ID_OF_ITEM')
: Fetches a single item in a table.getAll()
: Fetches all items from the table
App.tsx
Add new item
App.tsx
Update item
App.tsx
Delete item
App.tsx