You can use CData Connect AI to query SingleStore data through a SQL Server interface. Follow the procedure below to create a virtual database for SingleStore in Connect AI and start querying using Node.js.
CData Connect AI provides a pure MySQL, cloud-to-cloud interface for SingleStore, allowing you to easily query live SingleStore data in Node.js โ without replicating the data to a natively supported database. As you query data in Node.js, CData Connect AI pushes all supported SQL operations (filters, JOINs, etc) directly to SingleStore, leveraging server-side processing to quickly return SingleStore data.
Configure SingleStore Connectivity for NodeJS
Connectivity to SingleStore from NodeJS is made possible through CData Connect AI. To work with SingleStore data from NodeJS, we start by creating and configuring a SingleStore connection.
-
Log into Connect AI, click Sources, and then click Add Connection
๐ Adding a Connection
- Select "SingleStore" from the Add Connection panel
๐ Selecting a data source
-
Enter the necessary authentication properties to connect to SingleStore.
The following connection properties are required in order to connect to data.
- Server: The host name or IP of the server hosting the SingleStore database.
- Port: The port of the server hosting the SingleStore database.
- Database (Optional): The default database to connect to when connecting to the SingleStore Server. If this is not set, tables from all databases will be returned.
Connect Using Standard Authentication
To authenticate using standard authentication, set the following:
- User: The user which will be used to authenticate with the SingleStore server.
- Password: The password which will be used to authenticate with the SingleStore server.
Connect Using Integrated Security
As an alternative to providing the standard username and password, you can set IntegratedSecurity to True to authenticate trusted users to the server via Windows Authentication.
Connect Using SSL Authentication
You can leverage SSL authentication to connect to SingleStore data via a secure session. Configure the following connection properties to connect to data:
- SSLClientCert: Set this to the name of the certificate store for the client certificate. Used in the case of 2-way SSL, where truststore and keystore are kept on both the client and server machines.
- SSLClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
- SSLClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
- SSLClientCertType: The certificate type of the client store.
- SSLServerCert: The certificate to be accepted from the server.
Connect Using SSH Authentication
Using SSH, you can securely login to a remote machine. To access SingleStore data via SSH, configure the following connection properties:
- SSHClientCert: Set this to the name of the certificate store for the client certificate.
- SSHClientCertPassword: If a client certificate store is password-protected, set this value to the store's password.
- SSHClientCertSubject: The subject of the TLS/SSL client certificate. Used to locate the certificate in the store.
- SSHClientCertType: The certificate type of the client store.
- SSHPassword: The password that you use to authenticate with the SSH server.
- SSHPort: The port used for SSH operations.
- SSHServer: The SSH authentication server you are trying to authenticate against.
- SSHServerFingerPrint: The SSH Server fingerprint used for verification of the host you are connecting to.
- SSHUser: Set this to the username that you use to authenticate with the SSH server.
๐ Configuring a connection (Salesforce is shown)
-
Click Save & Test
-
Navigate to the Permissions tab in the Add SingleStore Connection page and update the User-based permissions.
๐ Updating permissions
Add a Personal Access Token
When connecting to Connect AI through the REST API, the OData API, or the Virtual SQL Server, a Personal Access Token (PAT) is used to authenticate the connection to Connect AI. It is best practice to create a separate PAT for each service to maintain granularity of access.
-
Click on the Gear icon () at the top right of the Connect AI app to open the settings page.
-
On the Settings page, go to the Access Tokens section and click Create PAT.
-
Give the PAT a name and click Create.
๐ Creating a new PAT
-
The personal access token is only visible at creation, so be sure to copy it and store it securely for future use.
With the connection configured and a PAT generated, you are ready to connect to SingleStore data from Node.js.
Query SingleStore from Node.js
The following example shows how to define a connection and execute queries to SingleStore with the SQL Server module. You will need the following information:
- server: tds.cdata.com
- port: 14333
- user: a Connect AI user (e.g. [email protected])
- password: the PAT for the above user
- database: The connection you configured for SingleStore (SingleStore1)
Connect to SingleStore data and start executing queries with the code below:
var sql = require('mssql')
var config = {
server: 'tds.cdata.com',
port: 14333,
user: '[email protected]', //update me
password: 'CONNECT_USER_PAT', //update me
options: {
encrypt: true,
database: 'SingleStore1'
}
}
sql.connect(config, err => {
if(err){
throw err ;
}
new sql.Request().query('SELECT * FROM Orders', (err, result) => {
console.dir(result)
})
});
sql.on('error', err => {
console.log("SQL Error: " ,err);
})