7.0.0
Initializes the connector for use. This is similar to connect()
, but stops short of
actually connecting to the server.
DbCon
:
Object.
Create a connection to the MapD server, generating a client and session ID.
Promise.DbCon
:
Object.
Connect to a MapD server:
var con = new DbCon()
.host('localhost')
.port('8080')
.dbName('myDatabase')
.user('foo')
.password('bar')
.connect()
.then((con) => console.log(con.sessionId()));
// ["om9E9Ujgbhl6wIzWgLENncjWsaXRDYLy"]
Create a connection to the MapD server, generating a client and session ID.
(Function)
An optional callback that takes
(err, success)
as its signature. Returns con singleton if successful.
Promise.DbCon
:
Object.
Connect to a MapD server:
var con = new DbCon()
.host('localhost')
.port('8080')
.dbName('myDatabase')
.user('foo')
.password('bar')
.connect((err, con) => console.log(con.sessionId()));
// ["om9E9Ujgbhl6wIzWgLENncjWsaXRDYLy"]
Disconnect from the server and then clear the client and session values.
Promise.DbCon
:
Object.
Disconnect from the server:
con.disconnect()
Disconnect from the server and then clear the client and session values.
(Function)
An optional callback that takes
(err, success)
as its signature. Returns con singleton if successful.
Promise.DbCon
:
Object.
Disconnect from the server:
con.sessionId() // ["om9E9Ujgbhl6wIzWgLENncjWsaXRDYLy"]
con.disconnect((err, con) => console.log(err, con))
con.sessionId() === null;
Get the status of the server as a TServerStatus object. This includes the server version number, whether the server is read-only, and whether backend rendering is enabled.
Promise<Object>
:
An object that contains information about the server status.
Get the server status:
con.getStatusAsync().then((result) => console.log(result))
// [{
// "read_only": false,
// "version": "3.0.0dev-20170503-40e2de3",
// "rendering_enabled": true,
// "start_time": 1493840131
// }]
Get the status of the server as a TServerStatus object. This includes the server version number, whether the server is read-only, and whether backend rendering is enabled.
(Function)
An optional callback that takes
(err, success)
as its signature. Returns an object that contains information about the server status.
Promise<Object>
:
An object that contains information about the server status.
Get the server status:
con.getStatus((err, result) => console.log(result))
// [{
// "read_only": false,
// "version": "3.0.0dev-20170503-40e2de3",
// "rendering_enabled": true,
// "start_time": 1493840131
// }]
Get information about the server hardware:
Promise<Object>
:
An object that contains hardware information.
Get server hardware information:
con.getHardwareInfoAsync().then((result) => console.log(result))
{
"hardware_info": [{
"num_gpu_hw": 2,
"num_cpu_hw": 12,
"num_gpu_allocated": 2,
"start_gpu": 0,
"host_name": "",
"gpu_info": [{
"num_sm": 28,
"clock_frequency_kHz": 1531000,
"memory": 12781682688,
"compute_capability_major": 6,
"compute_capability_minor": 1
}, {
"num_sm": 28,
"clock_frequency_kHz": 1531000,
"memory": 12782075904,
"compute_capability_major": 6,
"compute_capability_minor": 1
}]
}]
}
Get information about the server hardware:
(Function)
An optional callback that takes
(err, success)
as its signature. Returns an object that contains hardware information.
Promise<Object>
:
An object that contains hardware information.
Get server hardware information:
con.getHardwareInfo((err, result) => console.log(result))
{
"hardware_info": [{
"num_gpu_hw": 2,
"num_cpu_hw": 12,
"num_gpu_allocated": 2,
"start_gpu": 0,
"host_name": "",
"gpu_info": [{
"num_sm": 28,
"clock_frequency_kHz": 1531000,
"memory": 12781682688,
"compute_capability_major": 6,
"compute_capability_minor": 1
}, {
"num_sm": 28,
"clock_frequency_kHz": 1531000,
"memory": 12782075904,
"compute_capability_major": 6,
"compute_capability_minor": 1
}]
}]
}
Get the first geo file in an archive, if present, to determine if the archive should be treated as geo.
(String)
The base filename of the archive.
Promise<String>
:
Full path to the located geo file; otherwise, to the original archivePath.
Get the first geo file in an archive:
con.getFirstGeoFileInArchiveAsync('archive.zip', {}).then(res => console.log(res))
Gets a list of filenames found within an archive.
(String)
The base filename of the archive.
Promise<Array>
:
A list of filenames (strings)
Get the filenames found within an archive:
con.getFilesInArchiveAsync('archive.zip', {}).then(res => console.log(res))
Get a list of all users on the database for this connection.
Promise<Array>
:
A list of all users (strings).
Get a list of all users:
con.getUsersAsync().then(res => console.log(res))
Get a list of all roles on the database for this connection.
Promise<Array>
:
A list of all roles (strings).
Get a list of all roles:
con.getRolesAsync().then(res => console.log(res))
Get a list of all dashboards on the database for this connection.
Promise<Array<TDashboard>>
:
A list of all dashboards (Dashboard objects).
Get a list of all dashboards:
con.getDashboardsAsync().then(res => console.log(res))
Get a single dashboard.
(Number)
The ID of the dashboard.
Promise<TDashboard>
:
The dashboard (Dashboard object).
Get a dashboard:
con.getDashboardAsync().then(res => console.log(res))
Add a new dashboard to the server.
(String)
The name of the new dashboard.
(String)
The Base64-encoded state string of the new dashboard.
(String)
The numeric hash of the dashboard thumbnail.
(String)
Stringified metadata related to the view.
Promise
:
Returns a Promise.all result (array) of the IDs created on each client.
Add a new dashboard to the server:
con.createDashboardAsync('newSave', 'dashboardstateBase64', null, 'metaData').then(res => console.log(res))
Replace a dashboard on the server with new properties.
(Number)
The ID of the dashboard to replace.
(String)
The name of the new dashboard.
(String)
User ID of the owner of the dashboard.
(String)
The Base64-encoded state string of the new dashboard.
(String)
The numeric hash of the dashboard thumbnail.
(String)
Stringified metadata related to the view.
Promise
:
Returns empty if successful, rejects if any client failed.
Replace a dashboard on the server:
con.replaceDashboardAsync(123, 'replaceSave', 'owner', 'dashboardstateBase64', null, 'metaData').then(res => console.log(res))
Delete a dashboard object containing a value for the view_state
property.
(Number)
The ID of the dashboard.
Promise
:
Returns empty if successful, rejects if any client failed.
Delete a specific dashboard from the server:
con.deleteDashboardAsync(123).then(res => console.log(res))
Delete multiple dashboards
(Array)
An array of dashboard ids (numbers)
Promise
:
Returns empty if successful, rejects if any client failed.
Delete dashboards from the server:
con.deleteDashboardsAsync([123, 456]).then(res => console.log(res))
Share a dashboard (GRANT a certain set of permissions to a specified list of groups).
(Number)
The ID of the dashboard.
Promise
:
Returns empty if successful.
Share a dashboard:
con.shareDashboardAsync(123, ['group1', 'group2'], ['object1', 'object2'], ['perm1', 'perm2']).then(res => console.log(res))
Share multiple dashboards.
(Array)
An array of dashboard ids (numbers)
Promise
:
Returns empty if successful.
Share dashboards:
con.shareDashboardsAsync([123, 456], ['group1', 'group2'], ['perm1', 'perm2']).then(res => console.log(res))
Stop sharing a dashboard (REVOKE a certain set of permission from a specified list of groups).
(Number)
The ID of the dashboard.
Promise
:
Returns empty if successful.
Unshare a dashboard:
con.unshareDashboardAsync(123, ['group1', 'group2'], ['object1', 'object2'], ['perm1', 'perm2']).then(res => console.log(res))
Unshare multiple dashboards.
Promise
:
Returns empty if successful.
Unshare dashboards:
con.unshareDashboardsAsync([123, 456], ['group1', 'group2'], ['perm1', 'perm2']).then(res => console.log(res))
Get the list of users that a dashboard has been shared with; that is, those users who have been granted permissions to the dashboard.
(Number)
The ID of the dashboard.
Promise
:
Returns the list of users (array).
Get the list of grantees for a dashboard:
con.getDashboardGranteesAsync(123).then(res => console.log(res))
Get a list of database objects granted to a role; that is, those objects the role has permissions to access.
(String)
The name of the role.
Promise
:
Returns the list of database object names (strings).
Get list of accessible database objects for a role:
con.getDbObjectsForGranteeAsync('role').then(res => console.log(res))
Get the privileges for the current user for a specified database object type and ID.
(String)
The ID of the object (e.g. table name or dashboard ID).
(TDBObjectType)
The type of the database object.
Promise<Array<TDBObject>>
:
Returns the list of database objects for this type and ID, including their privs (property 'privs').
Get the list of accessible database objects for the current user:
con.getDbObjectPrivsAsync('table_name', 'TableDBObjectType').then(res => console.log(res))
Get all the roles assigned directly to a given username.
(String)
The username whose roles you wish to get.
Promise
:
A list of all roles assigned to the username.
Get all the roles assigned to a given username recursively (ie, roles assigned to the user, and roles assigned to those roles, and so on).
(String)
The username whose roles you wish to get.
Promise
:
A list of all roles assigned to the username.
Checks if the given user or role has a privilege(s) on a given object. Note that this check is
transative; if a user has been granted a privilege via a role, this will return true
.
(String)
The name of the user or role to check privileges for.
(String)
The name of the object to check privileges against (for example,
the database name, table name, etc.)
(TDBObjectType)
The type of object to check privileges against.
(TDBObjectPermissions)
An object containing the privileges to check. All
the privileges specified must be granted for this function to return true.
Boolean
:
true if all the specified privileges have been granted to the user/role,
false otherwise.
Check if user my_user
has the "view SQL Editor" privilege on the my_db
database:
con.hasDbPrivilegesAsync(
"my_user",
"my_db",
TDBObjectType.DatabaseDBObjectType,
new TDBObjectPermissions({
database_permissions_: new TDatabasePermissions(dbPrivs)
})
).then((res) =>
if(res) { console.log("Can view the SQL editor") }
)
Specialization of has_object_privilege
for checking database privileges of a user.
(String)
The name of the user or role to check privileges for.
(String)
The name of the database to check user privileges against.
(TDatabasePermissions)
An object specifying what privileges to check.
Boolean
:
true if the user/role has all the specified DB privileges, false otherwise.
Check if user my_user
has the "view SQL Editor" privilege on the my_db
database:
con.hasDbPrivilegesAsync("my_user", "my_db", {view_sql_editor_: true}).then(res =>
if(res) { console.log("Can view the SQL editor") }
)
Asynchronously get data from an importable file, such as a CSV or plaintext file with a header.
(String)
The name of the importable file.
Promise<TDetectResult>
:
An object that has
copy_params
and
row_set
.
Get data from table_data.csv:
var copyParams = new TCopyParams();
con.detectColumnTypesAsync('table_data.csv', copyParams).then(res => console.log(res))
// TDetectResult {row_set: TRowSet, copy_params: TCopyParams}
Submit a query to the database and process the results.
Promise.Object
:
The result of the query.
Create a query:
var query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'";
var options = {};
con.query(query, options).then((result) => console.log(result));
Submit a query to the database and process the results.
Promise.Object
:
The result of the query.
Create a query:
var query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'";
var options = {};
con.query(query, options, function(err, result) {
console.log(result)
});
Submit a query to validate that the backend can create a result set based on the SQL statement.
(String)
The query to perform.
Promise<Object>
:
The result of whether the query is valid.
Create a query and determine if it is valid:
var query = "SELECT count(*) AS n FROM tweets_nov_feb WHERE country='CO'";
con.validateQuery(query).then(res => console.log(res))
// [{
// "name": "n",
// "type": "INT",
// "is_array": false,
// "is_dict": false
// }]
Get the names of the databases that exist in the current session connection.
Promise<Array<Object>>
:
List of table objects containing the label and table names.
Get the list of tables from a connection:
con.getTablesAsync().then(res => console.log(res))
// [{
// label: 'obs', // deprecated property
// name: 'myTableName'
// },
// ...]
Get the names of the databases that exist in the current session connection.
Promise<Array<Object>>
:
List of table objects containing the label and table names.
Get the list of tables from a connection:
con.getTablesAsync((err, res) => console.log(res))
// [{
// label: 'obs', // deprecated property
// name: 'myTableName'
// },
// ...]
Get names and catalog metadata for tables that exist on the current session's connection.
Promise<Array<Object>>
:
The list of objects containing table metadata.
Get the list of tables with metadata from a connection:
con.getTablesWithMetaAsync().then(res => console.log(res))
[
{
name: 'my_table_name',
col_datum_types: [TDatumType::BOOL, TDatumType::DOUBLE],
is_view: false,
is_replicated: false,
shard_count: 0,
max_rows: -1
},
...]
Get names and catalog metadata for tables that exist on the current session's connection.
Promise<Array<TTableMeta>>
:
The list of objects containing table metadata.
Get the list of tables with metadata from a connection:
con.getTablesMetaAsync().then(res => console.log(res))
[
{
table_name: 'my_table_name',
col_datum_types: [TDatumType::BOOL, TDatumType::DOUBLE],
col_names: ['bool_col', 'double_col'],
is_view: false,
is_replicated: false,
shard_count: 0,
max_rows: -1
},
...]
Returns a list of available table function names
Promise.Array
:
An array of table function names (strings)
Returns a list of available runtime table function names
Promise.Array
:
An array of runtime table function names (strings)
(Array.String)
The table function names to retrieve details for
Promise.Array
:
An array of TUserDefinedTableFunction objects describing each supplied table function
Submits an SQL string to the backend and returns a completion hints object.
(String)
A fragment of SQL input.
(Object)
An options object continaing the current cursor position, 1-indexed from the start of
queryString
.
Promise.Array
:
An array of completion hints objects that contains the completion hints.
const queryString = "f";
const cursor = 1;
con.getCompletionHints(queryString, cursor, function(error, result) {
console.log(result)
});
[{
hints: ["FROM"],
replaced: "f",
type: 7
}]
Submits an SQL string to the backend and returns a completion hints object.
(String)
A fragment of SQL input.
(Object)
An options object continaing the current cursor position, 1-indexed from the start of
queryString
.
Promise.Array
:
An array of completion hints objects that contains the completion hints.
const queryString = "f";
const cursor = 1;
con.getCompletionHints(queryString, cursor, function(error, result) {
console.log(result)
});
[{
hints: ["FROM"],
replaced: "f",
type: 7
}]
Create an array-like object from TDatumType by changing the order of the string key and numerical value.
Undefined
:
This function does not return anything.
Get a list of field objects for a specified table.
(String)
Name of table containing field names.
Promise.Array<Object>
:
The formatted list of field objects.
Get the list of fields from a specific table:
con.getFields('flights', (err, res) => console.log(res))
// [{
name: 'fieldName',
type: 'BIGINT',
is_array: false,
is_dict: false
}, ...]
Get a list of field objects for a specified table.
(String)
Name of table containing field names.
Promise.Array<Object>
:
The formatted list of field objects.
Get the list of fields from a specific table:
con.getFields('flights', (err, res) => console.log(res))
// [{
name: 'fieldName',
type: 'BIGINT',
is_array: false,
is_dict: false
}, ...]
Create a table and persist it to the backend.
(String)
The name of the new table.
(Array<TColumnType>)
Fields in the new table.
(TCreateParams)
Properties to apply to the new table (e.g. replicated)
(Object)
Name | Description |
---|---|
options.useUnmodifiedRowDesc boolean
|
By default, createTableAsync calls createTable using properties from both rowDescObj and the descriptor last returned by detectColumnTypesAsync. If true, this simply calls createTable with the passed rowDescObj, removing the dependence on the previous detectColumnTypesAsync call |
Promise<undefined>
:
Generates an error if unsuccessful, or returns undefined if successful.
Create a new table:
con.createTable('mynewtable', [TColumnType, TColumnType, ...], 0).then(res => console.log(res));
// undefined
Import a delimited table from a file.
(String)
The name of the new table.
(String)
The name of the file containing the table.
(Array<TColumnType>)
A collection of metadata related to the table headers.
Import a geo table from a file.
(String)
The name of the new geo table.
(String)
The name of the file containing the table.
(Array<TColumnType>)
A colleciton of metadata related to the table headers.
Use for backend rendering. This method fetches a PNG image that is a render of the Vega JSON object. The Image will be a string if using browser-connector.js, or a Buffer otherwise.
Promise.Image
:
Base64 image.
Use for backend rendering. This method fetches a PNG image that is a render of the Vega JSON object. The Image will be a string if using browser-connector.js, or a Buffer otherwise.
(Number)
The widget ID of the calling widget.
(String)
The Vega JSON.
(Object)
The options for the render query.
Name | Description |
---|---|
options.compressionLevel Number
|
The PNG compression level. Range: 1 (low compression, faster) to 10 (high compression, slower). Default: 3. |
Promise.Image
:
Base64 image.
Used primarily for backend-rendered maps; fetches the row for a specific table that was last rendered at a pixel.
(Number)
The widget ID of the caller.
(TPixel)
The pixel. The lower-left corner is pixel (0,0).
(Number
= 2
)
The radius around the primary pixel to search within.
String
:
Current result nonce
Used primarily for backend-rendered maps; fetches the row for a specific table that was last rendered at a pixel.
(Number)
The widget ID of the caller.
(TPixel)
The pixel. The lower-left corner is pixel (0,0).
(Number
= 2
)
The radius around the primary pixel to search within.
String
:
Current result nonce
Get or set the session ID used by the server to serve the correct data. This is typically set by connect and should not be set manually.
(Number)
The session ID of the current connection.
(Number | DbCon)
:
The session ID or MapD connector itself.
Get the session ID:
con.sessionId();
// sessionID === 3145846410
Set the session ID:
var con = new DbCon().connect().sessionId(3415846410);
// NOTE: It is generally unsafe to set the session ID manually.
Get or set the connection server hostname. This is is typically the first method called after instantiating a new DbCon.
(String)
The hostname address.
(String | DbCon)
:
The hostname or MapD connector itself.
Set the hostname:
var con = new DbCon().host('localhost');
Get the hostname:
var host = con.host();
// host === 'localhost'
Get or set the connection port.
(String)
The port to connect on.
(String | DbCon)
:
The port or MapD connector itself.
Set the port:
var con = new DbCon().port('8080');
Get the port:
var port = con.port();
// port === '8080'
Get or set the username with which to authenticate.
(String)
The username with which to authenticate.
(String | DbCon)
:
The username or MapD connector itself.
Set the username:
var con = new DbCon().user('foo');
Get the username:
var username = con.user();
// user === 'foo'
Get or set the user password for authentication.
(String)
The password with which to authenticate.
(String | DbCon)
:
The password or MapD connector itself.
Set the password:
var con = new DbCon().password('bar');
Get the username:
var password = con.password();
// password === 'bar'
Get or set the name of the database to connect to.
(String)
The database to connect to.
(String | DbCon)
:
The name of the database or the MapD connector itself.
Set the database name:
var con = new DbCon().dbName('myDatabase');
Get the database name:
var dbName = con.dbName();
// dbName === 'myDatabase'
Configure whether raw query strings are logged to the console.
Used primarily for debugging; false
by default.
(Boolean)
Set to true to enable logging.
(Boolean | DbCon)
:
The current logging flag or MapD connector itself.
Set logging to true:
var con = new DbCon().logging(true);
Get the logging flag:
var isLogging = con.logging();
// isLogging === true
The name of the platform.
(String)
The platform; "heavydb" by default.
(String | DbCon)
:
The platform or MapD connector itself.
Set the platform name:
var con = new DbCon().platform('myPlatform');
Get the platform name:
var platform = con.platform();
// platform === 'myPlatform'
Get the number of connections that are currently open.
Number
:
The number of open connections.
Get the number of connections:
var numConnections = con.numConnections();
// numConnections === 1
The protocol to use for requests.
(String | DbCon)
:
The protocol or DbCon itself.
Set the protocol:
var con = new DbCon().protocol('http');
Get the protocol:
var protocol = con.protocol();
// protocol === 'http'
Disables logic that automatically tries to reconnect to the server if there's an error
(Boolean?)
If true, disables auto-reconnect
(Boolean | DbCon)
:
The status of auto-reconnect, or DbCon itself.
Generates a list of endpoints from the connection parameters.
Array<String>
:
List of endpoints.
Get the endpoints:
var con = new DbCon().protocol('http').host('localhost').port('8000');
var endpoints = con.getEndpoints();
// endpoints === [ 'http://localhost:8000' ]
Set the license for Trial or Enterprise
(String)
The key to install
(Object)
Protocol, host and port to connect to
Name | Description |
---|---|
config.protocol any
|
|
config.host any
|
|
config.port any
|
Promise<Object>
:
Claims or Error.
Get the license for Trial or Enterprise
(Object)
Protocol, host and port to connect to
Name | Description |
---|---|
config.protocol any
|
|
config.host any
|
|
config.port any
|
Promise<Object>
:
Claims or Error.
Converts a raw integer timestamp value from the DB into milliseconds. The DB timestamp value may represent seconds, ms, us, or ns depending on the precision of the column. This value is truncated or extended as necessary to convert to ms precision. The returned ms value is suitable for passing to the JS Date object constructor.
(Number)
The raw integer timestamp in the database.
(Number)
The precision of the timestamp column in the database.
Number
:
The equivalent timestamp in milliseconds.
Converts a Number/BigInt value to a Boolean
(BigInt)
A BigInt value
Boolean
:
The equivalent boolean value representing the buffer
Process the column-based results from the query in a row-based format. (Returning row-based results directly from the server is inefficient.)
(TRowSet)
The column-based data returned from a query.
(Boolean)
A flag that removes null rows from results.
Object
:
The formatted results of the query.
Determines how to process raw results when they return from the server.
(Boolean)
If enabled, shows on the console how long the query took to run.
(Function)
A function that updates internal query times on the connector.
(Object)
A list of options for processing the results.
Name | Description |
---|---|
options.isImage Boolean
|
Set to true when querying for backend-rendered images. |
options.eliminateNullRows Boolean
|
Removes null rows. |
options.query String
|
The SQL query string used only for logging. |
options.queryId Number
|
The ID of the query. |
options.conId Number
|
The unique connector identification. |
options.estimatedQueryTime String
|
The estimate of the query time. |
(Object)
The query result used to decide whether to process
as column or row results.
Object
:
result if image, otherwise formatted results.
Query for row-based results from the server. In general, is inefficient and should be avoided. Instead, use processColumnarResults and then convert the results to row-based format.
(TRowSet)
The row-based data returned from a query.
(Boolean)
Flag that removes null rows from results.
Object
:
The formatted results of the query.
<caption> Return row-based results directly from the server:
The information about a particular field in a given table.
Type: TTypeInfo
The types of the completion hint response object.
Type: completion_hints
The types of tables that uploaded through the importer TTableType.
Type: TTableType
Contains the result from calling detectColumnTypes.
Type: TDetectResult
(TCopyParams)
(TRowSet)
The data stored for a dashboard.
Type: TFrontendView
(String)
: The lookup hash for the dashboard thumbnail image.
(String)
: The timestamp from the last saved update.
(String)
: The name of the dashboard or the shortened share link hash.
(String)
: The Base64-encoded string containing the details about the current state of the dashboard.
The valid types for database field values.
Type: Object
(Number)
: =0
(Number)
: =1
(Number)
: =2
(Number)
: =3
(Number)
: =4
(Number)
: =5
(Number)
: =6
(Number)
: =7
(Number)
: =8
(Number)
: =9
(Number)
: =10
(Number)
: =11
(Number)
: =12
(Number)
: =13
(Number)
: =14
(Number)
: =20
(Number)
: =15
(Number)
: =16
(Number)
: =17
(Number)
: =18
(Number)
: =19
Import completion status of a table.
Type: TImportStatus
The value of an individual cell in a table.
Type: TDatumVal
The value and state of an individual data cell in a table.
Type: TDatum
A row of data in a table.
Type: TRow
Type: TColumnType
Contains parsed table data.
Type: TRowSet
The permissions granted by the server.
Type: TServerStatus
The configuration required to import a table into MapD. See detectColumnTypes for a usage example.
Type: TCopyParams
(String)
: =null
(String)
: =null
(String)
: =null
(String)
: ="" - The delimiter character; for example, comma,
[TAB]
, or pipe.
(String)
: =null
(Boolean)
: =null
(String)
: =null
(String)
: ="" - The token used by the table to express a null value; for example, some systems use 'nil' or 'none'.
(String)
: =null
(Boolean)
: =true - Indicates whether the string fields should be wrapped in quotes.
(Number)
: =null