Quick and easy relational data for your NodeJS apps.
- Install the module:
npm install springbase
- Create your database
- Start moving data
- It's free!
Easy to use
var springbase = require('springbase');
var conn = new springbase.data.Connection({
application: "1GmTdS2ayPts",
username: "<email>",
password: "<password>"
});
var query = conn.getQuery("qryStoreInventoryByZipCode");
query.on("ready", function() {
var reader = query.execute({ zipCode: 94611 });
reader.on("row", function(row) {
console.log("Found store:", row);
});
});
Cloud management interface
Create your tables and queries in an HTML5-based cloud IDE. No need to download anything.
SQL query support
Save parameterized queries for rapid recall and manipulation of data.
More examples
Insert into a table:
var table = conn.getTable("Stores");
table.on("ready", function() {
table.insert({
number: 115,
zipCode: 94105,
hours: "8 AM - 11 PM"
});
});
Update table rows:
// Change store hours for store with id 30
table.update(30, {
hours: "8 AM - 11 PM"
});
Delete table rows:
table.deleteRows(30);
Read all rows from a table:
var reader = table.openReader();
reader.on("ready", function() {
console.log("All stores:", reader.readAll());
});
API reference
Connection
class
in springbase.data
Provides access to Springbase objects and data. Create one of these first, then use it to access tables and queries.
Connection constructor
Requires a config object with the following properties:- application The ID of your Springbase database
(get this from Application->Settings in the IDE) - username Your Springbase username (email)
- password Your Springbase user password
var conn = new springbase.data.Connection({
application: "1GmTdS2ayPts",
username: "my-email@gmail.com",
password: "mypassword"
});
getTable
Get a Table by its name. Second parameter is an
optional callback to call when the table is ready to use, or listen for the "ready" event.
var table = conn.getTable("Products");
table.on("ready", function() {
// table is ready to use
});
getQuery
Get a Query by its name. Second parameter is an
optional callback to call when the query is ready to use, or listen for the "ready" event.
var query = conn.getQuery("qryStoresByZipCode", function() {
// query is ready to use
});
Query
class
in springbase.data
A saved query, created in the Springbase IDE.
Call execute or openReader, optionally with a set
of parameters, to run the query.
SELECT queries return a Reader
with a set of rows.
execute
Run the query. SELECT queries
will return a Reader; listen for the reader's "ready" event, or supply a
callback function as the second argument to execute(), to read the results.
Non-SELECT queries (UPDATE, INSERT, and DELETE) return a single number indicating how many rows were affected.
var query = conn.getQuery("qryStoresByZipCode", function() {
// query is ready to use
});
Table
class
in springbase.data
A data table, created in the Springbase IDE.
openReader
Returns a Reader containing all rows in the table (maximum 500).
To read more than 500 rows, make multiple requests, specifying a "start" parameter in the
config object (first argument).
var reader = table.openReader({
start: 1000 // start at 1001st record
});
reader.on("ready", function() {
// read rows
});
insertRows
Insert one or more rows into the table. The first argument is either a
single row object or an array of row objects. Each row object has named
properties matching the columns in the table, along with the values to insert.
Columns not explicitly provided will be inserted with the column's default value, if any, or NULL.
table.insertRows([{
"Hours": "10am - 7pm",
"Address1": "123 4th Street"
},{
"Address1": "303 Second Street"
}]);
updateRow
Update the row with the specified id (first argument), setting
column values based on the named properties in the second argument.
Third argument is an optional callback.
For more complex update criteria, create a saved UPDATE query and execute it using the Query class.
table.updateRow(5, {
"Hours": "10am - 7pm",
"Address1": "123 4th Street"
});
Reader
class
in springbase.data
A set of data records, loaded from a query or table.
Loop through the records using read or
get all records as an array using readAll.
The number of records is available in the recordCount
property.
read
Read the next row. Each row is an object with named properties matching the recordset's column names.
For example, if you obtained the Reader by calling Table.openReader,
the row's properties will match the table's column names.When no more rows are available, returns null.
var query = conn.getQuery("qryStoresByZipCode", function() {
var reader = query.execute({ zipCode: 94611 });
reader.on("ready", function() {
while (var row = reader.read()) {
console.log("Store hours:", row["Hours"]);
}
}
});
readAll
Read all rows and return them in the form of an array.
Each element in the returned array is a row identical to the ones returned by read.
var query = conn.getQuery("qryStoresByZipCode", function() {
var reader = query.execute({ zipCode: 94611 });
reader.on("ready", function() {
reader.readAll().map(function(row) {
console.log("Store hours:", row["Hours"]);
});
}
});
Found a problem with the documentation? Please report it on
the issue tracker.