db3.js is the db3 network javascript API and you can use it to write and query JSON documents against the db3 network. and you can build fully decentralized applications combining web3.js and db3.js
yarn add db3.js
const account = createRandomAccount()
const client = createClient('http://127.0.0.1:26619', '', account)
const nonce = await syncAccountNonce(client)
// create a database
const { db, result } = await createDocumentDatabase(client, 'desc')
const index: Index = {
path: '/name',
indexType: IndexType.StringKey,
}
// create a collection
const { collection, result } = await createCollection(
db,
'col',
[index]
)
// add a document
const [txId, block, order] = await addDoc(collection, {
name: 'book1',
author: 'db3 developers',
tag:'web3',
time: 1686285013,
})
// query document
const query = '/[name = book1]'
const resultSet = await queryDoc<Book>(
collection,
query)
Please ⭐️ this repository if this project helped you!
git clone https://github.com/dbpunk-labs/db3.js.git
git submodule update --recursive
cd tools && bash start_localnet.sh
git submodule update
# install the dependency
yarn
# generate the protobuf
make
# run test
yarn test
# format the code
yarn prettier --write src
# run benchmark
yarn benny-sdk