Connector for communicating with a SiriDB node
install.packages('siridbr')
library(siridbr)
siridb <- SiriDB(user="iris", password="siri", dbname="dbtest", server="localhost", port=9000L)
siridb$connect(function(err) {
if (!is.null(err)) {
cat('Connection error: ', err)
} else {
siridb$close()
}
})
Create a new SiriDB Client. This creates a new client but connect()
must be used to connect.
siridb <- SiriDB(
user="iris", # database user
password="siri", # password
dbname="dbtest", # database name
server="localhost", # server address
port=9000L # server port
)
Connect to SiriDB. A callback function can be used to check if the connect is successful.
siridb$connect(function(err) {
# success: err is NULL
# error: err is a string with an error message
if (!is.null(err)) {
cat('Connection error: ', err)
}
})
Query SiriDB. Requires a string containing the query and a callback function to catch the result.
The callback function will be called with two arguments:
- first argument: A response Object
- second argument: Number indicating the status. The status is 0 when successful or a negative value in case of an error. (see Status codes for the possible status codes)
siridb$query("select * from /.*series/", function(resp, status) {
// success: status is 0 and resp is an Object containing the data
// error: status < 0 and resp.error_msg contains a description about the error
if (status) {
cat('Query error: ', resp$error_msg, status)
} else {
cat(resp)
}
})
Insert time series data into SiriDB. Requires an Array with at least one series Object.string containing the query and a callback function to catch the result.
The callback function will be called with two arguments:
- first argument: A response Object
- second argument: Number indicating the status. The status is 0 when successful or a negative value in case of an error. (see Status codes for the possible status codes)
series = list(
list(
name='example', # name
points=list(
list(timestamp=1500000000, value=0L), # time-stamp, value
list(timestamp=1500000900, value=1L) # etc.
)
)
)
siridb$insert(series, function(resp, status) {
// success: status is 0 and resp.success_msg contains a description about the successful insert
// error: status < 0 and resp.error_msg contains a description about the error
if (status) {
cat('Insert error: ', resp$error_msg, status)
} else {
cat(resp.success_msg) # insert message
}
})
Close the connection.
siridb$close()
TODO
Sometimes its useful to act on a specific error, for example you might want to retry the request in case of ERR_SERVER
while a ERR_INSERT
error indicates something is wrong with the data.
The following status codes can be returned:
SiriDB.errcodes.ERR_MSG
(-64) General errorSiriDB.errcodes.ERR_QUERY
(-65) Most likely a syntax error in the querySiriDB.errcodes.ERR_INSERT
(-66) Most likely the data is invalid or corruptSiriDB.errcodes.ERR_SERVER
(-67) The server could not perform the request, you could try another SiriDB serverSiriDB.errcodes.ERR_POOL
(-68) At least one pool has no online SiriDB serverSiriDB.errcodes.ERR_ACCESS
(-69) The database user has not enough privileges to process the request,SiriDB.errcodes.ERR_RUNTIME
(-70) Unexpected error has occurred, please check the SiriDB logSiriDB.errcodes.ERR_NOT_AUTHENTICATED
(-71) The connection is not authenticatedSiriDB.errcodes.ERR_CREDENTIALS
(-72) Credentials are invalidSiriDB.errcodes.ERR_UNKNOWN_DB
(-73) Trying to authenticate to an unknown databaseSiriDB.errcodes.ERR_LOADING_DB
(-74) The database is loading
Show version info.
siridb$version()