在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:ipfs-shipyard/ipfs-live-db开源软件地址:https://github.com/ipfs-shipyard/ipfs-live-db开源编程语言:开源软件介绍:ipfs-live-db
Install$ npm install ipfs-live-db --save ImportIn the browser environment, you can either use this library by including it and bundling your app together with it (using browserify or webpack, for instance), or you can in Node.js or in a browser with a bundler:const DB = require('ipfs-live-db') Using a script tag in a browser<!-- loading the minified version -->
<script src="https://unpkg.com/ipfs-live-db/dist/browser.min.js"></script>
<!-- loading the human-readable (not minified) version -->
<script src="https://unpkg.com/ipfs-live-db/dist/browser.js"></script> Now you can access this library using the Instantiateconst db = DB([options]) Arguments:
APIdb.define([typeName:String, ]typeDefinition:Object)Defines and returns a type. const TodoList = db.define('TodoList', {
type: 'Array',
of: {
name: 'TodoItem'
type: 'Object'
}
})
const list = TodoList() You can chain them: db.define('TodoItem', {
type: 'Object'
})
const TodoList = db.define('TodoList', {
type: 'Array',
of: 'TodoItem' // not necessary if you don't want a CRDT
}) or simply nest them: const TodoItem = db.define({
type: 'Object'
})
const TodoList = db.define('TodoList', {
type: 'Array',
of: TodoItem
}) Built-in typesThe basic types that come build-in are 'Map' and 'Array'. The rest is up to you. Instantiatedb.create(type, id:String)Creates an instance for a given type. Depending on the base type, it returns either a specized Example: const id = 'some id'
const item = db.create('TodoItem', id) Mapitem.get(key:String)Returns the value for the key. item.set(key:String, value:Any)Sets the value for that key item.delete(key:String)Deletes a property item.keys()Returns all keys for all values item.observe(observer:Function)The
item.observeDeep(observer:Function)Same as .observe, but catches events from all children (if they support
item.unobserve(observer:Function)Deactivates an observer. Arrayitem.insert(position:Number, contents:Array)Inserts item.push(contents)Inserts item.delete(position, length)Deletes content. The length parameter is optional and defaults to 1. item.toArray()Returns the complete content as an array. item.get(position:Number)Returns the content at a given position. item.observe(observer:Function)The
item.observeDeep(observer:Function)Same as .observe, but catches events from all children (if they support .observeDeep).
item.unobserve(observer:Function)Deactivates an observer. LicenseMIT ContributeFeel free to join in. All welcome. Open an issue! This repository falls under the IPFS Code of Conduct. License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论