1.12.24 • Published 4 years ago
dbdriver v1.12.24
ShareChat DB Driver - nodeJS wrapper
//Installation
npm install dbdriver
export DB_DRIVER_DOMAIN="http://dev.dbdriver.cldcvr.com"
export DB_DRIVER_AUTH=<Auth token here>
const db = require("dbdriver")
getWithProjection
//Used to fetch row details with projections
Params:
tableName : "user"
primaryKeyMap : { id: { N: "106209821" }}
projectionExpression: "id, #views"
expressionAttributeNames: {"#views": "views"}
Response:
BODY: { Item: { id: { N: '106209821' }, views: { S: '301' } } }
Example:
//get data with projections
//function(tableName,primaryKeyMap,projectionName,expressionAttributeNames,consistentRead,callback)
db.getWithProjection("user", primaryKeyMap, "id, #views", {"#views": "views"}, true, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
batchGetWithProjection
//Used to fetch multiple rows with projections
Params:
tableName : "post_counters"
keyArray : [{ id: { N: "106199029" }}, { id: { N: "106209821" }}]
projectionExpression: "id, impressions, likeCount, shares, favouriteCount, views, #c"
expressionAttributeNames: {"#c":"uniqueShareCount"}
Response:
BODY:
[ { favouriteCount: { S: '1' },
id: { N: '106199029' },
impressions: { S: '1' },
likeCount: { S: '2' },
shares: { S: '5' },
uniqueShareCount: { S: '5' },
views: { S: '345' } },
{ favouriteCount: { S: '3' },
id: { N: '106209821' },
shares: { S: '1' },
uniqueShareCount: { S: '1' },
videoPlayCount: { S: '71' },
views: { S: '301' } } ]
Example:
//batch get items with projections
//function(tableName, keyArray, projectionName, expressionAttributeNames, callback)
db.batchGetWithProjection("user", keyArray, "id, impressions, likeCount, shares, favouriteCount, views, #c", expressionAttributes, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
batchGet
//Used to fetch multiple rows by Keys
Params:
tableName : "post_counters"
keyArray : [{ id: { N: "106199029" }}, { id: { N: "106209821" }}]
Response:
BODY:
[ { favouriteCount: { S: '1' },
id: { N: '106199029' },
impressions: { S: '1' },
likeCount: { S: '2' },
shares: { S: '5' },
uniqueShareCount: { S: '5' },
views: { S: '345' } },
{ favouriteCount: { S: '3' },
id: { N: '106209821' },
shares: { S: '1' },
uniqueShareCount: { S: '1' },
videoPlayCount: { S: '71' },
views: { S: '301' } } ]
Example:
//batch get items
db.batchGet("post_counters", keyArray, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
incr
//increments a counter in the keyValue table
Parameters:
key :"counter/userIds"
Response:
32 (the incremented value)
Example:
//increment a key
db.incr("counter/userIds", (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
put
//Updates a row in BigTable. Keys are required inside attrMap
Parameters:
tableName: "post_counters"
attrMap: {
id: { N: "101306988" },
name: { S: "abc" },
phoneNo: { N: "3145306" }
}
Response:
BODY:{ Attributes:
{ favouriteCount: { S: '1' },
id: { N: '101306988' },
likeCount: { S: '3' },
name: { S: 'abc' },
phoneNo: { N: '3145306' },
views: { S: '215' } } }
Example:
//function(tableName, attrMap, conditionalExp, conditionalVal, callback)
bt.put(tableName, attrMap, null, null, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
batchPut
//Updates multiple rows in BigTable. Keys are required inside attrMap.
Parameters:
tableName: "post_counters"
arrAttrMap: [{ id: { N: "106209821" }}, { id: { N: "106199029" }}, { id: { N: "763453" }}]
Response:
BODY: null
Example:
//
db.batchPut(tableName, arrAttrMap, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
query
Used to query starting from a row key.
parameters:
tableName: "post_counters",
onlyCount: false,
limit: 20,
sortAscending: true,
startFrom: null,
hashExp: "id =",
hashVal: = {
"S": "101306988"
}
Response:
BODY: { Items:
[ { favouriteCount: [Object],
id: [Object],
likeCount: [Object],
name: [Object],
phoneNo: [Object],
views: [Object] } ],
Count: 1,
ScannedCount: 1,
LastEvaluatedKey: { id: { N: '101306988' } } }
Example:
db.query("post_counters", "", false, 10, true, null, "id=", hasVal, null, null, (err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
queryWithProjection
Used to query starting from a row key with projections
parameters:
tableName: "post_counters",
onlyCount: false,
limit: 20,
sortAscending: true,
startFrom: null,
hashExp: "id =",
hashVal: = {
"S": "101306988"
}
projectionExpression:"id, likeCount, name",
ExpressionAttributeNames:{}
Response:
BODY: { Items:
[ {
id: [Object],
likeCount: [Object],
name: [Object] ],
Count: 1,
ScannedCount: 1,
LastEvaluatedKey: { id: { N: '101306988' } } }
Example:
//function(tableName, indexName, onlyCount, limit, sortAscending, startFrom, hashExp, hashVal, rangeExp, rangeVal, projectionsName, expressionAttributeNames, callback)
db.queryWithProjection("post_counters", "", false, 10, true, null, "id=", hasVal, null, null,"id, likeCount, name",null,(err, data) => {
if (err) {
console.log(err.data)
}
else if (!data) {
console.log("No data")
}
else{
console.log(data)
}
})
update
Used to update a record
parameters:
tableName: "post_counters",
primaryKeyMap: { id: { S: "106209821" }}
updateExp: "SET views = :v",
conditionalExp: "attribute_exists(id)",
attrVals: {
":v":{
"S":"40000"
}
}
Response:
BODY: { favouriteCount: { S: '3' },
id: { N: '106209821' },
shares: { S: '1' },
uniqueShareCount: { S: '1' },
videoPlayCount: { S: '71' },
views: { S: '40000' } }
Example:
const BTinput = { id: { S: "106209821" }}
const updateExp = "SET views = :v"
const condExp = "attribute_exists(id)"
const expAttr = {
":v":{
"S":"40000"
}
}
db.update("post_counters", BTinput, updateExp, condExp, expAttr, (err, data) => {
console.log(err, data)
})
1.12.24
4 years ago
1.12.23
4 years ago
1.12.21
4 years ago
1.12.20
4 years ago
1.12.22
4 years ago
1.12.19
4 years ago
1.12.18
4 years ago
1.12.17
4 years ago
1.12.16
4 years ago
1.12.15
4 years ago
1.12.14
4 years ago
1.12.13
4 years ago
1.12.12
4 years ago
1.12.10
4 years ago
1.12.11
4 years ago
1.12.9
4 years ago
1.12.7
4 years ago
1.12.6
4 years ago
1.12.8
4 years ago
1.12.5
4 years ago
1.12.4
4 years ago
1.12.3
4 years ago
1.12.2
4 years ago
1.12.1
4 years ago
1.12.0
4 years ago
1.11.0
4 years ago
1.10.1
4 years ago
1.10.0
4 years ago
1.0.9
4 years ago
1.0.8
4 years ago
1.0.7
4 years ago
1.0.6
4 years ago
1.0.5
4 years ago
1.0.4
4 years ago
1.0.3
4 years ago
1.0.2
4 years ago
1.0.1
4 years ago
1.0.0
4 years ago