- Source:
Methods for tables.
Methods
(static) addField(tableName, fieldToAdd) → {Promise.<{status: 201, statusText: 'Created', message: string}>}
- Source:
- Since:
- 1.0.0
Adds a field to table tableName
.
Note (incompatible types): Some properties are not compatible with some field types. For example, it is not possible to specify a Prefix
for a field whose Type
is 'TIMESTAMP'
. Use care and caution when creating field definitions.
Example
// add a simple text field (max 255 characters) to the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);
async function addFieldToTable() {
const fieldDef = {
"Name": "Sample_Field",
"Type": "STRING",
"Unique": false,
"Description": "Sample data field to collext smaller textual data (max 255 characters)",
"DisplayOrder": 1,
"Label": "Sample Field",
}
const addFieldResult = await caspio.tables.addField('Demo_Users', fieldDef);
console.log(addFieldResult);
return addFieldResult;
}
addFieldToTable();
// sample return value
{
status: 201,
statusText: 'Created',
message: "The field 'Sample_Field' was successfully added to the following table: 'Demo_Users'."
}
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fieldToAdd |
Object | Definition of field to add to the specified table Properties
|
Returns:
Object with information about the attempted creation of the new field for the specified table (i.e., status
, statusText
, and message
).
- Type
- Promise.<{status: 201, statusText: 'Created', message: string}>
(static) create(tableName, fieldDefinitions) → {Promise.<{status: 201, statusText: 'Created', message: string}>}
- Source:
- Since:
- 1.0.0
- See:
-
Caspio documentation for creating tables
Creates a new table using the name and field definitions provided (i.e., tableName
and fieldDefinitions
, respectively). This is often a slow method and takes a while for the request to be processed by Caspio's servers.
Note (incompatible types): Some properties are not compatible with some field types. For example, it is not possible to specify a Prefix
for a field whose Type
is 'TIMESTAMP'
. Use care and caution when creating field definitions. The example that accompanies this method shows examples of each field Type
creation.
Example
// create a table titled 'my_new_table' that includes an example
// of the creation of each field type that Caspio has to offer
const caspio = require('caspio-sdk')(caspioCredentials);
async function createTable() {
const tableName = 'my_new_table';
const tableColumnDefs = [
{
"Name": "my_id",
"Type": "AUTONUMBER",
"Unique": true,
"Description": "Data Type: Autonumber\n\nDescription: An automatically-assigned ID field. The value is incremented by 1 for each new record and cannot be changed except by resetting it for the entire table.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000), Number, Integer, Currency",
"DisplayOrder": 1,
"Label": "Example field with Type of AUTONUMBER",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Format": "001",
"Prefix": "some_prefix",
"Name": "my_prefixed_autonumber",
"Type": "PREFIXED AUTONUMBER",
"Unique": true,
"Description": "Data Type: Prefixed Autonumber\n\nDescription: An automatically-assigned ID field with the ability to add a prefix.\n\nUse the Options area to configure the prefix and number format of the ID code to be generated.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
"DisplayOrder": 2,
"Label": "Example field with Type of PREFIXED AUTONUMBER",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "guid",
"Type": "GUID",
"Unique": true,
"Description": "Data Type: GUID\n\nDescription: A system-generated and globally-unique identifier value, typically used as a complex unique value.\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
"DisplayOrder": 3,
"Label": "Type GUID",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Format": "0U",
"Prefix": "",
"Length": 8,
"Name": "random_id",
"Type": "RANDOM ID",
"Unique": true,
"Description": "Data Type: Random ID\n\nDescription: A unique system-generated random ID field with the ability to add a prefix as well as define the length and composition of characters, digits, or both.\n\nUse the Options area to configure the prefix and number of characters the ID code should contain. You can also specify whether to include alphabet characters only, numbers only, or both (alphanumeric).\n\nExamples: Customer_ID, Record_ID\n\nConversion Compatibility: Text (255), Text (64000)",
"DisplayOrder": 4,
"Label": "Type: RANDOM ID",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Full_Name",
"Type": "STRING",
"Unique": false,
"Description": "Data Type: Text (255)\n\nDescription: Used for a string of text of up to 255 alphanumeric characters and/or symbols. This data type is the most common data type and yields the fastest performance in searches.\n\nYou can also use this data type for numeric characters that are not used as numbers in calculations or formatting--such as phone numbers, zip codes, and social security numbers. Not doing so impacts formatting and prevents proper sorting by this field.\n\nExamples: First_Name, State, Phone, Zip_Code\n\nConversion Compatibility: Text (64000), File (provided that the text field contains proper file paths)",
"DisplayOrder": 5,
"Label": "Type: TEXT",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Bio",
"Type": "TEXT",
"Unique": false,
"Description": "Data Type: Text (64000)\n\nDescription: Used for a long string of text of up to 64,000 alphanumeric characters and/or symbols.\n\nUse this data type for description fields or other lengthy text data. Otherwise, use Text (255), which performs much faster.\n\nExamples: Description, Comments\n\nConversion Compatibility: Text (255) (longer strings are truncated), File (provided that the text field contains proper file paths)",
"DisplayOrder": 6,
"Label": "Type: STRING",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "password",
"Type": "PASSWORD",
"Unique": false,
"Description": "Data Type: Password\n\nDescription: Used for storing user passwords.\n\nThe value of this field is always encrypted and cannot be seen in Datasheet or DataPages.\n\nExamples: Password\n\nConversion Compatibility: None",
"DisplayOrder": 7,
"Label": "Type: PASSWORD",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Favorite_Number",
"Type": "NUMBER",
"Unique": false,
"Description": "Data Type: Number\n\nDescription: Used for decimal numbers.\n\nExamples: Weight, height, area, percentage values\n\nConversion Compatibility: Text (255), Text (64000), Integer (decimal values are truncated), Currency (allows up to four decimal points)",
"DisplayOrder": 8,
"Label": "Type: NUMBER",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Age",
"Type": "INTEGER",
"Unique": false,
"Description": "Data Type: Integer\n\nDescription: Used for numbers that do not have a decimal point, can be used as IDs and in relationships.\n\nExamples: Age, number of children\n\nConversion Compatibility: Text (255), Text (64000), Number, Currency",
"DisplayOrder": 9,
"Label": "Type: INTEGER",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Salary",
"Type": "CURRENCY",
"Unique": false,
"Description": "Data Type: Currency\n\nDescription: Used for money fields in any currency.\n\nExamples: Price, Salary\n\nConversion Compatibility: Text (255), Text (64000), Integer (decimal values are truncated)",
"DisplayOrder": 10,
"Label": "Type: CURRENCY",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Birthday",
"Type": "DATE/TIME",
"Unique": false,
"Description": "Data Type: Date/Time\n\nDescription: Used for date and time data.\n\nDataPages automatically display a calendar picker for date/time fields. 'Precision' is specified in the DataPage and is used to configure which part of the date or time part is used.\n\nUse the Options area to specify whether or not to allow blank values in this field.\n\nExamples: Followup_Date, Date_of_Birth\n\nConversion Compatibility: Text (255), Text (64000), Timestamp",
"DisplayOrder": 11,
"Label": "Type: DATE/TIME",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Married",
"Type": "YES/NO",
"Unique": false,
"Description": "Data Type: Yes/No\n\nDescription: Used for fields that allow only two possible values: yes or no (true or false).\n\nBy default a Yes/No input field appears as a checkbox in forms.\n\nExamples: Active_User, Requested_Newsletter, Published\n\nConversion Compatibility: Text (255), Text (64000), Number",
"DisplayOrder": 12,
"Label": "YES/NO",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Profile_Picture",
"Type": "FILE",
"Unique": false,
"Description": "Data Type: File\n\nDescription: Used to associate files with a record.\n\nFile fields allow your app users to upload files using a web form. Files are stored in your database and can be used in DataPages.\n\nFiles can also be accessed in the Files area of All Assets, organized in a file folder structure.\n\nExamples: Profile_Photo, Resume, Contract\n\nConversion Compatibility: Text (255) may be truncated, Text (64000)",
"DisplayOrder": 13,
"Label": "FILE",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"OnInsert": true,
"OnUpdate": false,
"TimeZone": "UTC",
"Name": "timestamp",
"Type": "TIMESTAMP",
"Unique": false,
"Description": "Data Type: Timestamp\n\nDescription: A timestamp is a type of smart field that automatically records the date and time when a record is submitted and/or updated.\n\nUse the Options area to configure the time zone and the general behavior of the timestamp.\n\nExamples: Date_Submitted, Date_Updated\n\nConversion Compatibility: Text (255), Text (64000), Date/Time",
"DisplayOrder": 14,
"Label": "Type: TIMESTAMP",
"UniqueAllowNulls": false,
"IsFormula": false
},
{
"Name": "Favorite_Words",
"Type": "LIST-STRING",
"Unique": false,
"Description": "Data Type: List\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - String for text values of up to 255 characters.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
"DisplayOrder": 15,
"Label": "LIST-STRING",
"UniqueAllowNulls": false,
"IsFormula": false,
"ListField": ["25", "Coffee", "Doggo", "Goober", "Jolly", "Malapropism"]
},
{
"Name": "Favorite_Numbers",
"Type": "LIST-NUMBER",
"Unique": false,
"Description": "Data Type: tbd\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - Number for numeric values of up to 15 digits.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
"DisplayOrder": 16,
"Label": "LIST-NUMBER",
"UniqueAllowNulls": false,
"IsFormula": false,
"ListField": [18, 42, 91, 777, 89]
},
{
"Name": "Favorite_Dates",
"Type": "LIST-DATE/TIME",
"Unique": false,
"Description": "Data Type: tbd\n\nDescription: A special data type for storing a collection of strings, numbers or dates in a single field. (List - Date for date or date/time values.)\n\nExamples: Allergies, Pizza_Toppings\n\nConversion Compatibility: None",
"DisplayOrder": 17,
"Label": "LIST-DATE/TIME",
"UniqueAllowNulls": false,
"IsFormula": false,
"ListField": ["1991-07-30T15:32:57", "2019-01-20T00:00:00", "2020-06-08T00:00:00", "2021-02-02T00:00:00"]
}
]
const creationResult = await caspio.tables.create(tableName, tableColumnDefs);
console.log(creationResult);
return creationResult;
}
createTable();
// sample return value
{
status: 201,
statusText: 'Created',
message: "Table 'my_new_table' has been created successfully."
}
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of the table |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fieldDefinitions |
Array.<Object> | Definitions of the fields to be created in the new table Properties
|
Returns:
Object with information about the attempted creation of the specified table (i.e., status
, statusText
, and message
).
- Type
- Promise.<{status: 201, statusText: 'Created', message: string}>
(static) createRecord(tableName, recordValuesObj, optionsopt) → {Promise.<({status: 201, statusText: 'Created', message: string}|{status: 201, statusText: 'Created', message: string, createdRecord: object})>}
- Source:
- Since:
- 1.0.0
Inserts record recordValuesObj
into table tableName
(i.e., creates a record).
Example
// create and return a record in the 'Demo_Users' table with a 'Name' field value of 'Osment'
// and an 'Email' field value of 'Osment@google.com'
const caspio = require('caspio-sdk')(caspioCredentials);
async function createTableRecord() {
const newRecordObj = {
Name: "Osment",
Email: "Osment@google.com",
}
const creationResult = await caspio.tables.createRecord('Demo_Users', newRecordObj, { row: true });
console.log(creationResult);
return creationResult;
}
createTableRecord();
// sample return value
{
status: 201,
statusText: 'Created',
message: "Record successfully created in 'Demo_Users' table.",
createdRecord: {
User_ID: 'QNFPG6OT',
Name: 'Osment',
Email: 'Osment@google.com',
Role: '',
Active: false
}
}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
||||||||||||
recordValuesObj |
object | Object with key-value pairs in the form Note (warnings about creating a record with list field values): If you are trying to create the values for a record's First, you have to know the numeric values of the keys for the key-value pairs that make up a Second, if you happen to specify an index value that does not currently exist in a list field's definition, then you'll get something like the following The whole thing is janky as hell and thus not recommended unless you really know what you're doing (even then you might get unlucky). |
||||||||||||
options |
object |
<optional> |
{ 'row': false }
|
The Properties
|
Returns:
Object with information about the attempted creation of the provided record (i.e., status
, statusText
, message
, and createdRecord
if the options
argument was passed as { 'row': true }
)
- Type
- Promise.<({status: 201, statusText: 'Created', message: string}|{status: 201, statusText: 'Created', message: string, createdRecord: object})>
(static) definition(tableName) → {Promise.<Array.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>>}
- Source:
- Since:
- 1.0.0
Returns the definition of table tableName
as an array of field definitions (objects).
Example
// get the table definition of the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);
async function getTableDefinition() {
const definition = await caspio.tables.definition('Demo_Users');
console.log(definition);
return definition;
}
getTableDefinition();
// sample return value
[
{
Format: '0U',
Prefix: '',
Length: 8,
Name: 'User_ID',
Type: 'RANDOM ID',
Unique: true,
Description: '',
DisplayOrder: 1,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
},
{
Name: 'Name',
Type: 'STRING',
Unique: false,
Description: '',
DisplayOrder: 2,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
},
{
Name: 'Email',
Type: 'STRING',
Unique: true,
Description: '',
DisplayOrder: 3,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
},
{
Name: 'Password',
Type: 'PASSWORD',
Unique: false,
Description: '',
DisplayOrder: 4,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
},
{
Name: 'Role',
Type: 'STRING',
Unique: false,
Description: '',
DisplayOrder: 5,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
},
{
Name: 'Active',
Type: 'YES/NO',
Unique: false,
Description: '',
DisplayOrder: 6,
Label: '',
UniqueAllowNulls: false,
IsFormula: false
}
]
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
Returns:
Array of field definitions (objects) where the properties of the objects depend on the field definition (e.g., a field with Type
of 'RANDOM ID'
may have a Length
property as part of the field definition object whereas other fields would not)
- Type
- Promise.<Array.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>>
(static) deleteField(tableName, fieldName) → {Promise.<{status: 200, statusText: 'OK', message: string}>}
- Source:
- Since:
- 1.0.0
Deletes field fieldName
from table tableName
(this may not be possible if other objects depend on this field such as triggered actions, authentications, etc.).
Example
// remove the field 'Sample_Field' from table 'Demo_Users'
const caspio = require('caspio-sdk')(caspioCredentials);
async function deleteTableField() {
const deleteResult = await caspio.tables.deleteField('Demo_Users', 'Sample_Field');
console.log(deleteResult);
return deleteResult;
}
deleteTableField();
// sample return value
{
status: 200,
statusText: 'OK',
message: "The field 'Sample_Field' in table 'Demo_Users' was successfully deleted."
}
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
fieldName |
string | Name of field (case-insensitive) |
Returns:
Object with information about the attempted removal of the specified field from the specified table (i.e., status
, statusText
, and message
).
- Type
- Promise.<{status: 200, statusText: 'OK', message: string}>
(static) deletePasswordFieldValue(tableName, passwordFieldName, whereClause) → {Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>}
- Source:
- Since:
- 1.0.0
Resets (i.e., removes) the password value in field passwordFieldName
of table tableName
for all records that match the provided WHERE
clause query (i.e., whereClause
).
Example
// removes the value in field 'Password' of table 'Demo_Users'
// for all records that have an Email field value of 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);
async function removePasswordValue() {
const whereClause = `Email = 'Edd36@yahoo.com'`;
const removeResult = await caspio.tables.deletePasswordFieldValue('Demo_Users', 'Password', whereClause);
console.log(removeResult);
return removeResult;
}
removePasswordValue();
// sample return value
{
status: 200,
statusText: 'OK',
recordsAffected: 1,
message: "Password value(s) successfully reset (i.e., removed) for field 'Password' in table 'Demo_Users' for 1 record(s)."
}
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
passwordFieldName |
string | Name of field with |
whereClause |
string |
|
Returns:
Object with information about the attempted resetting or removal of all password values for the matched records (i.e., status
, statusText
, recordsAffected
, and message
).
- Type
- Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>
(static) deleteRecords(tableName, whereClause) → {Promise.<{status: 200, statusText: 'OK', message: string, recordsAffected: number}>}
- Source:
- Since:
- 1.0.0
Deletes all records from table tableName
that match whereClause
(i.e., the provided WHERE
clause).
Example
// delete all records from the 'Demo_Users' table that have
// an 'Email' field value of 'Osment@google.com'
const caspio = require('caspio-sdk')(caspioCredentials);
async function deleteTableRecords() {
const whereClause = `Email = 'Osment@google.com'`;
const deleteResult = await caspio.tables.deleteRecords('Demo_Users', whereClause);
console.log(deleteResult);
return deleteResult;
}
deleteTableRecords();
// sample return value
{
status: 200,
statusText: 'OK',
message: "1 record(s) in table 'Demo_Users' successfully deleted.",
recordsAffected: 1
}
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
whereClause |
string |
|
Returns:
Object with information about the attempted deletion of the records matched by the WHERE
clause (i.e., status
, statusText
, message
, and recordsAffected
)
- Type
- Promise.<{status: 200, statusText: 'OK', message: string, recordsAffected: number}>
(static) description(tableName) → {Promise.<{Name: string, Note: string}>}
- Source:
- Since:
- 1.0.0
Returns the description of the table (i.e., a description of table tableName
).
Example
// get the description of the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);
async function getTableDescription() {
const description = await caspio.tables.description('Demo_Users');
console.log(description);
return description;
}
getTableDescription();
// sample return value
{ Name: 'Demo_Users', Note: '' }
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of the table (case-insensitive) |
Returns:
Object with the name of the table (i.e., Name
) and a note about the table (i.e., Note
)
- Type
- Promise.<{Name: string, Note: string}>
(static) fieldDefinition(tableName) → {Promise.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>}
- Source:
- Since:
- 1.0.0
Returns the definition of field fieldName
from table tableName
.
Example
// get the definition of the field 'Sample_Field' from the 'Demo_Users' table
const caspio = require('caspio-sdk')(caspioCredentials);
async function getFieldDef() {
const fieldDef = await caspio.tables.fieldDefinition('Demo_Users', 'Sample_Field');
console.log(fieldDef);
return fieldDef;
}
getFieldDef();
// sample return value
{
Name: 'Sample_Field',
Type: 'STRING',
Unique: false,
Description: 'Sample data field to collext smaller textual data (max 255 characters)',
DisplayOrder: 1,
Label: 'Sample Field',
UniqueAllowNulls: false,
IsFormula: false
}
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
Returns:
Field definition (object) where the properties of the object depend on the field definition (e.g., a field with Type
of 'RANDOM ID'
may have a Length
property as part of the field definition object whereas other fields would not)
- Type
- Promise.<{Name: string, Type: string, Unique: boolean, UniqueAllowNulls: boolean, Label: string, Description: string, DisplayOrder: number, OnInsert: boolean, OnUpdate, boolean, TimeZone: string, Format: string, Prefix: string, Length: number, IsFormula: boolean, ListField: object}>
(static) getRecords(tableName, selectionCriteriaObjopt) → {Promise.<Array.<Object>>}
- Source:
- Since:
- 1.0.0
Returns all records from the table that satisfy the provided query criteria (i.e., selectionCriteriaObj
). Pagination is automatically handled to ensure all records matching the provided criteria are returned.
Note (potential strain on memory resources): If the query provided results in many thousands or millions of records needing to be returned, then this may cause a strain on memory resources (since all returned records are held in memory when using this method). Consider using the getRecordsStreamToFile
method in such an instance where all returned records can be streamed to a file in batches of 1000
records (i.e., the maximum number of records Caspio's REST API will respond with for any request).
Example
// get records from the 'Demo_Users' table using the query criteria
// provided in the criteriaObj object
const caspio = require('caspio-sdk')(caspioCredentials);
async function getTableRecords() {
const criteriaObj = {
select: 'Email, ROW_NUMBER() OVER (PARTITION BY Role ORDER BY User_ID) AS rnk_num',
where: `Name LIKE '%ed%'`,
orderBy: 'rnk_num'
}
const tableRecords = await caspio.tables.getRecords('Demo_Users', criteriaObj);
console.log(tableRecords);
return tableRecords;
}
getTableRecords();
// sample return value
[
{ "Email": "Edwardo.Roberts@gmail.com", "rnk_num": 1 },
{ "Email": "Frederick_Sanford@yahoo.com", "rnk_num": 1 },
{ "Email": "Winifred.Stamm41@hotmail.com", "rnk_num": 2 },
{ "Email": "Fred.Daugherty41@hotmail.com", "rnk_num": 2 },
{ "Email": "Alan.Schroeder@gmail.com", "rnk_num": 3 },
...
{ "Email": "Eliane.Schroeder@hotmail.com", "rnk_num": 81 },
{ "Email": "Jedediah_Bednar33@yahoo.com", "rnk_num": 81 },
{ "Email": "Edyth3@gmail.com", "rnk_num": 82 },
{ "Email": "Magdalen84@hotmail.com", "rnk_num": 82 },
{ "Email": "Edyth_Mayer@yahoo.com", "rnk_num": 83 },
{ "Email": "Eddie_Predovic14@hotmail.com", "rnk_num": 84 },
{ "Email": "Francesca_Medhurst39@yahoo.com", "rnk_num": 85 },
{ "Email": "Jedediah.Mitchell@hotmail.com", "rnk_num": 86 },
{ "Email": "Wilfred_Funk20@gmail.com", "rnk_num": 87 },
{ "Email": "Mohamed.Hammes@hotmail.com", "rnk_num": 88 },
{ "Email": "Frieda_Strosin@gmail.com", "rnk_num": 89 },
{ "Email": "Ted.Anderson94@yahoo.com", "rnk_num": 90 },
{ "Email": "Jedediah.Runolfsson60@yahoo.com", "rnk_num": 91 },
{ "Email": "Destiny.Schroeder@hotmail.com", "rnk_num": 92 },
{ "Email": "Edwina.Barrows@yahoo.com", "rnk_num": 93 },
{ "Email": "Carlie_Bednar@gmail.com", "rnk_num": 94 },
{ "Email": "Ebony25@gmail.com", "rnk_num": 95 },
{ "Email": "Lexi81@hotmail.com", "rnk_num": 96 },
{ "Email": "Frederique.Kuhn86@gmail.com", "rnk_num": 97 },
{ "Email": "Winifred_Aufderhar63@yahoo.com", "rnk_num": 98 },
{ "Email": "Edd_Carroll0@hotmail.com", "rnk_num": 99 }
]
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
|||||||||||||||||||||||||||
selectionCriteriaObj |
Object |
<optional> |
{}
|
Object that specifies the criteria to be used in constructing the query. Valid properties include the following: In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on. Note: Usage of window functions when expecting more than Properties
|
Returns:
An array of objects representing the records retrieved from the specified table (i.e., tableName
) that were obtained by the query provided (i.e., selectionCriteriaObj
).
- Type
- Promise.<Array.<Object>>
(static) getRecordsPaginated(tableName, selectionCriteriaObjopt) → {Promise.<Array.<Object>>}
- Source:
- Since:
- 1.0.0
Returns records in a paginated fashion from table tableName
that satisfy the provided query criteria (i.e., selectionCriteriaObj
).
Example
// get the default of 100 records from the Demo_Users table using
// the query criteria provided in the criteriaObj object
const caspio = require('caspio-sdk')(caspioCredentials);
async function getPaginatedTableRecords() {
const criteriaObj = {
select: 'Email, ROW_NUMBER() OVER (PARTITION BY Role ORDER BY User_ID) AS rnk_num',
where: `Name LIKE '%ed%'`,
orderBy: 'rnk_num'
}
const tableRecords = await caspio.tables.getRecordsPaginated('Demo_Users', criteriaObj);
console.log(tableRecords);
return tableRecords;
}
getPaginatedTableRecords();
// sample return value
[
{ Email: 'Frederick_Sanford@yahoo.com', rnk_num: 1 },
{ Email: 'Edwardo.Roberts@gmail.com', rnk_num: 1 },
{ Email: 'Fred.Daugherty41@hotmail.com', rnk_num: 2 },
{ Email: 'Winifred.Stamm41@hotmail.com', rnk_num: 2 },
{ Email: 'Winifred.Friesen@hotmail.com', rnk_num: 3 },
{ Email: 'Alan.Schroeder@gmail.com', rnk_num: 3 },
...
{ Email: 'Meredith.Botsford50@hotmail.com', rnk_num: 48 },
{ Email: 'Braeden63@gmail.com', rnk_num: 48 },
{ Email: 'Eddie_Tromp@hotmail.com', rnk_num: 49 },
{ Email: 'Ned39@gmail.com', rnk_num: 49 },
{ Email: 'Edna92@hotmail.com', rnk_num: 50 },
{ Email: 'Soledad.Collins84@yahoo.com', rnk_num: 50 }
]
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
||||||||||||||||||||||||||||||||||||||||||
selectionCriteriaObj |
Object |
<optional> |
{}
|
Object that specifies the criteria to be used in constructing the query. Valid properties include the following: In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on. Note: Usage of window functions (e.g., Properties
|
Returns:
An array of objects representing the records retrieved from the specified table (i.e., tableName
) that were obtained by the query provided (i.e., selectionCriteriaObj
).
- Type
- Promise.<Array.<Object>>
(static) getRecordsStreamToFile(tableName, filePath, selectionCriteriaObjopt) → {void}
- Source:
- Since:
- 1.0.0
Streams all records from the table (i.e., tableName
) that satisfy the provided query criteria (i.e., selectionCriteriaObj
) to a file (i.e., filePath
). Pagination is automatically handled to ensure all records matching the provided criteria are streamed to the specified file. Records are streamed in batches of 1000
records (Caspio's rate limit for returning records). Useful when you need to process huge amounts of data but do not want to hold everything in memory.
Example
// stream all records from the 'Demo_Users' table to the 'StreamedDemoUsers.json' file
const caspio = require('caspio-sdk')(caspioCredentials);
async function streamTableRecordsToFile() {
await caspio.tables.getRecordsStreamToFile('Demo_Users', 'StreamedDemoUsers.json');
}
streamTableRecordsToFile();
// no return value
Parameters:
Name | Type | Attributes | Default | Description | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
|||||||||||||||||||||||||||
filePath |
string | Path of file to write to (file path should have an extension of |
|||||||||||||||||||||||||||
selectionCriteriaObj |
Object |
<optional> |
{}
|
Object that specifies the criteria to be used in constructing the query. Valid properties include the following: In large part, the query being constructed resembles most queries constructed using SQL (specifically the SQL Server dialect since Caspio uses SQL Server under the hood). Consult a Caspio rep to find which version your account is running on. Note: Usage of window functions when expecting more than Properties
|
Returns:
No value is returned
- Type
- void
(static) listing() → {Promise.<Array.<string>>}
- Source:
- Since:
- 1.0.0
Returns an array of strings where each string represents an available table for a Caspio account.
Example
// get list of all table names linked to a Caspio account
const caspio = require('caspio-sdk')(caspioCredentials);
async function getTableNames() {
const tableNames = await caspio.tables.listing();
console.log(tableNames);
return tableNames;
}
getTableNames();
// sample return value
[
...,
'Demo_Physicians',
...
]
Returns:
Array of strings representing table names for a Caspio account
- Type
- Promise.<Array.<string>>
(static) passwordFields(tableName) → {Promise.<Array.<string>>}
- Source:
- Since:
- 1.0.0
Returns a list of the names of all password fields in table tableName
(i.e., an array of the names of whatever fields are present in table tableName
that have a Type
of 'PASSWORD'
).
Example
// get list of all fields with a Type of 'PASSWORD' from the table 'Demo_Users'
const caspio = require('caspio-sdk')(caspioCredentials);
async function getTablePasswordFields() {
const passwordFields = await caspio.tables.passwordFields('Demo_Users');
console.log(passwordFields);
return passwordFields;
}
getTablePasswordFields();
// sample return value
[ 'Password' ]
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
Returns:
Array of strings representing the names of fields present in the specified table that have a Type
of 'PASSWORD'
- Type
- Promise.<Array.<string>>
(static) updateFieldDefinition(tableName, fieldName, updatedFieldDef) → {Promise.<{status: 200, statusText: 'OK', message: string}>}
- Source:
- Since:
- 1.0.0
Updates field fieldName
of table tableName
using properties and values of the updatedFieldDef
object.
Note 1 (importance of New
prefix): It is critically important that all updated field properties be prepended with New
in the provided updatedFieldDef
object; otherwise, an error will be thrown. For example, if you want to update the Type
of a field from 'STRING'
to 'TEXT'
, then you need to specify the updatedFieldDef
object as { ..., 'NewType': 'TEXT', ... }
as opposed to { ..., 'Type': 'TEXT', ... }
. The presence of 'New'
is required.
Note 2 (warning about list types): Be wary of updating a field with a Type
of LIST-STRING|NUMBER|DATE/TIME
for reasons outlined in this method's documentation.
Example
// update the field 'Sample_Field' in table 'Demo_Users'
// to have a Type of 'TEXT' instead of 'STRING'
const caspio = require('caspio-sdk')(caspioCredentials);
async function updateTableField() {
const updatedFieldDef = {
"NewType": "TEXT"
}
const updateResult = await caspio.tables.updateFieldDefinition('Demo_Users', 'Sample_Field', updatedFieldDef);
console.log(updateResult);
}
updateTableField();
// sample return value
{
status: 200,
statusText: 'OK',
message: "The field 'Sample_Field' in table 'Demo_Users' was successfully updated."
}
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fieldName |
string | Name of field (case-sensitive) |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
updatedFieldDef |
Object | Definition of field to update in table Properties
|
Returns:
Object with information about the attempted update of the specified field for the specified table (i.e., status
, statusText
, and message
).
- Type
- Promise.<{status: 200, statusText: 'OK', message: string}>
(static) updatePasswordFieldValue(tableName, passwordFieldName, newPasswordValue, whereClause) → {Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>}
- Source:
- Since:
- 1.0.0
Updates the password field passwordFieldName
in table tableName
with a value of newPasswordValue
for all records that are matched by the provided WHERE
clause query (i.e., whereClause
).
Example
// update the value in field 'Password' of table 'Demo_Users'
// to 'myPassword!' for all records in table 'Demo_Users' that have
// an Email field value of 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);
async function updateTablePassword() {
const whereClause = `Email = 'Edd36@yahoo.com'`;
const updateResult = await caspio.tables.updatePasswordFieldValue('Demo_Users', 'Password', 'myPassword!', whereClause);
console.log(updateResult);
return updateResult;
}
updateTablePassword();
// sample return value
{
status: 200,
statusText: 'OK',
recordsAffected: 1,
message: "Password value(s) successfully updated for field 'Password' in table 'Demo_Users' for 1 record(s)."
}
Parameters:
Name | Type | Description |
---|---|---|
tableName |
string | Name of table (case-insensitive) |
passwordFieldName |
string | Name of field in table |
newPasswordValue |
string | New password value |
whereClause |
string |
|
Returns:
Object with information about the attempted update of all password values for the matched records (i.e., status
, statusText
, recordsAffected
, and message
).
- Type
- Promise.<{status: 200, statusText: 'OK', recordsAffected: number, message: string}>
(static) updateRecords(tableName, whereClause, newRecordValuesObj, optionsopt) → {Promise.<({status: 200, statusText: 'OK', message: string, recordsAffected: number}|{status: 200, statusText: 'OK', message: string, recordsAffected: number, updatedRecords: Array.<Object>})>}
- Source:
- Since:
- 1.0.0
Updates all records in table tableName
matched by whereClause
(i.e., the provided WHERE
clause) with values from the newRecordValuesObj
object.
Example
// Update the 'Name' field in the 'Demo_Users' table to have a value of
// 'Eddy Rath' for all records that have an 'Email' field with value 'Edd36@yahoo.com'
const caspio = require('caspio-sdk')(caspioCredentials);
async function updateTableRecords() {
const whereClause = `Email = 'Edd36@yahoo.com'`;
const newValuesObj = {
Name: "Eddy Rath"
}
const updateResult = await caspio.tables.updateRecords('Demo_Users', whereClause, newValuesObj, { rows: true });
console.log(updateResult);
return updateResult;
}
updateTableRecords();
// sample return value
{
status: 200,
statusText: 'OK',
message: "1 record(s) affected. Note: If the number of affected records is higher than expected, then be sure to check any triggered actions associated with the 'Demo_Users' table, which can cause various records in other tables to be affected.",
recordsAffected: 1,
updatedRecords: [
{
User_ID: '7NQC2PHT',
Name: 'Eddy Rath',
Email: 'Edd36@yahoo.com',
Role: 'Admin',
Active: false
}
]
}
Parameters:
Name | Type | Attributes | Default | Description | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
tableName |
string | Name of table (case-insensitive) |
||||||||||||
whereClause |
string |
|
||||||||||||
newRecordValuesObj |
object | Object with key-value pairs in the form Note (warnings about updating a record's list field values): If you are trying to update the values for a record's First, you have to know the numeric values of the keys for the key-value pairs that make up a Second, if you happen to specify an index value that does not currently exist in a list field's definition, then you'll get something like the following Third, if you update records by only specifying fields with a Fourth (as if you needed another reason to avoid updating values in list fields), if The whole thing is janky as hell and thus not recommended unless you really know what you're doing (even then you might get unlucky). |
||||||||||||
options |
object |
<optional> |
{ 'rows': false }
|
The Properties
|
Returns:
Object with information about the attempted update of the records matched by the WHERE
clause (i.e., status
, statusText
, message
, recordsAffected
, and updatedRecords
if the options
argument was passed as { 'rows': true }
)
- Type
- Promise.<({status: 200, statusText: 'OK', message: string, recordsAffected: number}|{status: 200, statusText: 'OK', message: string, recordsAffected: number, updatedRecords: Array.<Object>})>