Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Application-friendly RethinkDB client
new Penseur.Db(name, [options])
Creates a new Db
object where:
name
- name of the database to use. Default is 'test'
.options
- optional configuration:
host
- string containing the host to connect to. Default is 'localhost'
port
- port to connect on. Default is 28015
.authKey
- string containing an established authorization keyuser
- string containing the user you want to perform actions as. Default is 'admin'
password
- string containing the users passwordtimeout
- number indicating the number of seconds to wait for a connection to be established before timing out. Default is 20
seconds.ssl
- ssl settings when RethinkDB requires a secure connection. This setting is passed to the RethinkDB module.
ca
- certificate as a Buffer used for establishing a secure connection to rethink, see RethinkDB connect documentationtest
- boolean indicating if the Db
actions should take place. Useful for testing scenarios, do not use in production.extended
- object that is used to extend the members of the table objects.onConnect
- function to execute when a connection is established.onError
- function to execute when an error occurs. Signature is function(err)
where err
is an error object.onDisconnect
- function to execute when a disconnection occurs. Signature is function(willReconnect)
where willReconnect
is a boolean indicating if the connection will be reestablished.reconnect
- boolean indicating if the connection should be reestablished when interruptedreconnectTimeout
- number of milliseconds to wait between reconnect attempts, when false
there is no timeout. Defaults to 100
db.connect(callback)
Create a connection to the database. callback
is a function with the signature function(err)
that is executed when the connection is established or an error occurs establishing the connection.
db.close([next])
Close all database connections.
db.establish([tables], callback)
Note that this can alter data and indexes, not intended of production use.
Establish a connection if one doesn't exist and create the database and tables if they don't already exist. This function also decorates the db
object with helper properties to for using each of the tables.
[tables]
- array of strings with the name of each table to createcallback
- function with signature function(err)
that is executed when everything succeeds or an error is encountered.db.disable(table, method, [options])
Only available when Db
is constructed in test mode. Disable a specific method from being performed on a table, used for testing.
table
- name of tablemethod
- name of method on table to disableoptions
- optional object with the following properties
value
- value to return when the method is called. Can be an error object to simulate errors.db.enable(table, method)
Only available when Db
is constructed in test mode. Enable a disabled method on a table, used for testing.
table
- name of tablemethod
- name of method on table to enabledb.r
Property that contains the RethinkDB module.
After a database connection exists and tables are established then the Db
object is decorated with properties for each table name containing various helper function. Below are the available functions for each table.
db[table].get(id, [options, ] callback)
Retrieve a record in the table
with the given id
. id
itself can be an array of id
values if you want to retrieve multiple records.
id
- unique identifier of record to retrieve. Can be an array with values for each ID to retrieve.options
- optional object with the following properties
sort
- table key to sort results usingorder
- 'descending'
or 'ascending'
for sort order, Defaults to 'ascending'
from
- index in result set to selectcount
- number of records to return in resultsfilter
- properties to pluck from the resultscallback
- function with function(err, results)
signaturedb[table].all(callback)
Retrieve all records for a table.
callback
- function with function(err, results)
signaturedb[table].exist(id, callback)
Determine if a record in the table
exists with the provided ID
id
- unique identifier of record to retrieve. Can be an array with values for each ID to retrieve.callback
- function with function(err, exists)
signaturedb[table].query(criteria, callback)
Perform a query on the table using the provided criteria. Criteria is available on the Db
object and is listed in the criteria section below.
criteria
- db criteria functions chained togethercallback
- function with function(err, results)
signaturedb[table].single(criteria, callback)
Retrieve a single record from the provided criteria.
criteria
- db criteria functions chained togethercallback
- function with function(err, result)
signaturedb[table].count(criteria, callback)
Retrieve the number of records in the table that match the given criteria.
criteria
- db criteria functions chained togethercallback
- function with function(err, count)
signaturedb[table].insert(items, [options, ] callback)
Create new record(s) in the table. Each item can specify a unique id
property or allow rethink to generate one for them.
items
- item object or array of items to insert into the tableoptions
- optional object with the following properties
merge
- boolean, when true any conflicts with existing items will result in an update, when false an error is returnedchunks
- maximum number of updates to send to the database at the same timecallback
- function with function(err, keys)
signaturedb[table].update(ids, changes, callback)
Update an existing record with the provided changes.
ids
- an identifier or array of identifiers of records to update in the tablechanges
- the parts of the record to change and the values to change the parts tocallback
- function with function(err)
signaturedb[table].update(updates, [options, ] callback)
Update an existing record with the provided changes.
updates
- an array of records to update (each must include an existing primary key)options
- optional settings where:
chunks
- maximum number of updates to send to the database at the same timecallback
- function with function(err)
signaturedb[table].remove(criteria, callback)
Remove the records in the table that match the given criteria.
criteria
- db criteria functions chained togethercallback
- function with function(err)
signaturedb[table].empty(callback)
Remove all records in the table.
callback
- function with function(err)
signaturedb[table].sync(callback)
Wait until all operations are complete and all data is persisted on permanent storage. Note that this function shouldn't be necessary for normal conditions.
callback
- function with function(err)
signaturedb[table].index(indexes, callback)
Create the secondary indexes
on the table. callback
is executed when all of the indexes are created.
indexes
- a string or array of strings for each index to createcallback
- function with function(err)
signaturedb[table].changes(criteria, [options,] [callback])
Subscribe to changes matching the given criteria for the table.
criteria
- db criteria functions chained togetheroptions
- optional object with the following properties
handler
- handler function to execute when changes occur. When provided the callback
function can be omitted.reconnect
- boolean, reconnect if the connection to the feed is interruptedinitial
- boolean, include the initial results in the change feedcallback
- function with function(err, changes)
signatureDb.or(values)
Db.contains(values[, options])
Db.not(values)
Db.unset()
Db.increment(value)
Db.append(value[, options])
Db.override(value)
Db.is(operator, values, ...and)
Db.by(index, values)
FAQs
Lightweight RethinkDB wrapper
The npm package penseur receives a total of 5 weekly downloads. As such, penseur popularity was classified as not popular.
We found that penseur demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.