Guidelines
- Introduction
- Installation
- Quick Start
Guides
- Introductions
- Build local test node
- Smart Contract - ABI Files
- Smart Contract——JS Contract
- Deploy Contracts
- Test Contract
- Develop DApp Client
Smart Contracts
- Contract Introduction
- ABI File
- Database
- Account Authority
- Call In-contract
- Notification
System Contracts
- Resources
- Account
- Permission
Token Contracts
- Transfer
- Token
- Token Exchange
- Contract Sub-Wallet
Node Guide
- Node Introduction
- Add to nodes network
- Node Data Persistence
Access Guide
- FO 接入安全指南
Database
Introduction
- In order to persist data to the database, and provide the data query capability and services, we will quote the FIBOS db module.
- Database operations require 3 modules, Respectively is: db, table and DBIterator。
To access the database
1 | const table = db.table(scope, code, indexes); |
- table:The table name of the data table defined in the abi file
- scope: The name of the publisher of contract pointed to
- code:The account_name to which the data in table belongs to
- index:index
db is the global module in FIBOS, The data tables we defined in the abi file will be mounted under the db module, This way we can access the data table defined in the abi file through the db module.
We will demonstrate the addition, deletion and modification of the data table:
The operation on the data table is written in the JS contract!
Save
1 | exports.emplace = param => { |
Save the data to the data table via the emplace
function under the table
module.
View
1 | exports.find = param => { |
Find data from the data table via the find
function under the table
module, Returning a DBIterator. The data property in DBIterator shows the data we want to query. For details, please refer to DBIterator in the API.
Modify
1 | exports.update = param => { |
Modify the data from the data table via the update
function under the DBIterator
module, We can modify the data property in DBIterator by looking up the data, and finally save and modify it with ‘update’.
Delete
1 | exports.remove = param => { |
The specified data is deleted from the data table via the remove
function under the DBIterator
module.
Set up index
1 | const indexes = { |
The above code defines one or more indexes, Add the indexes parameter when accessing the table, so you can use the index when working on the table.
Index based query
1 | var itr = players.indexes.age.find({age:48,weight:100}); |
Conclusion
- Module db is the base module in FIBOS - a database access module that can be used to create and manipulate database resources.
- The data table can be added, deleted, and changed through the db object.