8000 GitHub - Rock-520/db3.js: DB3 Network Javascript API
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Rock-520/db3.js

 
 

Repository files navigation

What is db3.js

GitHub release (latest by date) npm Coveralls branch

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

why

Play with db3.js

Install db3.js

yarn add db3.js

Use db3.js in action

Build db3 client

Connect to db3 network with db3 browser wallet

// the key seed
const mnemonic ='...'
// create a wallet
const wallet = DB3BrowserWallet.createNew(mnemonic, 'DB3_SECP256K1')
// build db3 client
const client = new DB3Client('http://127.0.0.1:26659', wallet)

Connect to db3 network with metamask

const wallet = new MetamaskWallet(window)
const client = new DB3Client('http://127.0.0.1:46659', wallet)

Create a database

const [dbId, txId] = await client.createDatabase()
const {db} = initializeDB3('http://127.0.0.1:26659', dbId, wallet)

Create a collection

// add a index to collection
const indexList: Index[] = [
            {
                name: 'idx1',
                id: 1,
                fields: [
                    {
                        fieldPath: 'name',
                        valueMode: {
                            oneofKind: 'order',
                            order: Index_IndexField_Order.ASCENDING,
                        },
                    },
                ],
            },
]
// create a collecion
const collectionRef = await collection(db, 'cities', indexList)
// add a doc to collection
const result = await addDoc(collectionRef, {
    name: 'beijing',
    address: 'north',
})
// get all docs from collection
const docs = await getDocs(collectionRef)

Show Your Support

Please ⭐️ this repository if this project helped you!

Contribution

1. Checkout

git clone https://github.com/dbpunk-labs/db3.js.git
git submodule update --recursive

2. Run DB3 Localnet

cd tools && bash start_localnet.sh

3. Run Testcase

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

About

DB3 Network Javascript API

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 98.6%
  • Shell 1.1%
  • Makefile 0.3%
0