
A CRAB-based ORM for BigchainDB.

CRAB is the CRUD model in databases applied to blockchains:
Create | Create |
Read | Retrieve |
Update | Append |
Delete | Burn |
Breaking changes
- **Version 3.x ** of js-driver-orm changes namespacing of data storage and retrieval. Using new version with old data will brake it!
Table of Contents
Setup
$ npm install bigchaindb-orm
Usage
import Orm from 'bigchaindb-orm'
const bdbOrm = new Orm(
"https://test.bigchaindb.com/api/v1/",
{
app_id: "Get one from testnet.bigchaindb.com",
app_key: "Get one from testnet.bigchaindb.com"
}
)
bdbOrm.define("myModel", "https://schema.org/v1/myModel")
const aliceKeypair = new bdbOrm.driver.Ed25519Keypair()
Examples
All examples need bdbOrm initialized as described in usage
Example: Create an asset
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
})
.then(asset => {
console.log(asset.id)
})
Example: Retrieve assets
bdbOrm.models.myModel
.retrieve()
.then(assets => {
console.log(assets.map(asset => asset.id))
})
Example: Append a transaction
"Update" (Database) => "Append" (Blockchain)
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
})
.then(asset => {
return asset.append({
toPublicKey: aliceKeypair.publicKey,
keypair: aliceKeypair,
data: { key: 'updatedValue' }
})
})
.then(updatedAsset => {
console.log(updatedAsset.data)
})
Example: Burn an asset
"Delete" (Database) => "Burn" (Blockchain)
:exclamation:Burning assets does not delete them! It moves control of asset from users keypair to unfulfillable one.:exclamation:
bdbOrm.models.myModel
.create({
keypair: aliceKeypair,
data: { key: 'dataValue' }
})
.then(asset => {
return asset.burn({
keypair: aliceKeypair
})
})
.then(burnedAsset => {
console.log(burnedAsset.data)
})
License
Copyright 2018 BigchainDB GmbH
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.