infinitedb v1.1.4
InfiniteDB
Client
Installation
Run npm install infinitedb
in your project
Require client using
const InfiniteDB = require('infinitedb')
Usage
List databases
let host = { hostname: '127.0.0.1', port: 8176 }
InfiniteDB.listDatabases(host).then(result => {
console.log(result)
}).then(error => {
console.log(error)
})
Create database
let host = { hostname: '127.0.0.1', port: 8176 }
let responsibilities = { number: { start:0, end: 10000 } }
InfiniteDB.createDatabase(host, 'DBNAME', responsibilities).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
Connect to database
let host = { hostname: '127.0.0.1', port: 8176 }
let database = new InfiniteDB(host, 'DBNAME')
database.connect().then(() => {
console.log('Connected to database!')
}).catch(error => {
console.log(error)
})
List tables
database.listTables.then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
Create table
For fields syntax please look at Server documentation
let fields = {}
database.createTable('TABLENAME', fields).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
Insert into table
let object = {}
database.insert('TABLENAME', object).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
Query from table
For request syntax please look at Server documentation
let request = {}
database.get('TABLENAME', request).then(result => {
console.log(result)
}).catch(error => {
console.log(error)
})
Server
Installation
Clone this repo https://github.com/MeshSocialNetwork/InfiniteDB.git
Run npm install
Create directory database/
Create config file database/config.json
with content:{ "hostname": "127.0.0.1", "port": "8176" }
API
GET /databases
Returns list of databases
POST /database
Create a new database
Request body:
{
"name": "DBNAME",
"responsibilities": { "start": 0, "end": 10000 }
}
POST /database/:name/join
Join an existing database (from another peer)
Request body:
{
"peer": {
"hostname": "127.0.0.1",
"port": "8176"
},
"responsibilities": { "start": 0, "end": 10000 },
"joinKey": "JOINKEY"
}
The joinKey can be found in database/DBNAME/database.json
GET /database/:name
Get tables with fields and responsibilities of database
GET /datbase/:name/tables
Get list of table names for database
POST /database/:name/table
Create new table
Request body:
{
"name": "tablename"
"fields": {
"testfield": {
"type": "text"
},
"testfield2": {
"type": "text",
"indexed": true
"unique": true
},
"testfield3": {
"type": "text",
"indexed": true,
"distributed": true
},
"testfield4": {
"type": "text",
"indexed": true,
"distributed": true,
"external": true
},
"testfield5": {
"type": "number",
"indexed": true,
"distributed": true
},
"testfield6": {
"type": "boolean",
"indexed": true
}
}
}
POST /database/:name/table/:tableName/get
Query table
Request body:
{
"where": {
"field": "testfield2",
"operator": "=",
"value": "testvalue",
"and": {
"field": "testfield5",
"operator": ">",
"value": 10
"or": {
"field": "testfield5",
"operator": "<",
"value": 10,
"or": {
"field": "testfield5",
"operator": "><",
"value": "10-20",
"and": {
"field": "testfield4",
"operator": "match",
"value": "testmatch"
}
}
}
}
},
"implement": [
{
"from": {
"table": "othertable",
"field": "otherfield"
},
"field": "testfield",
"as": "testalias"
}
],
"sort": {
"field": "testfield5",
"direction": "DESC"
},
"skip": 0,
"limit": 50
}
POST /database/:name/table/:tableName/insert
Insert into table
Request body:
{
"object": {
"fieldname": "fieldvalue"
}
}
POST /database/:name/table/:tableName/update
Update existing object in table (must have indexed unique field)
Request body:
{
"object": {
"indexedUniqueField", "value"
}
}
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago