Install

Run the following command to install the connector from the root of your project:

npm install --save @latitude-data/mssql-connector

How to configure sources

The sources files must be inside the queries/ folder.

To know how the source hierarchy works, please, visit How to configure sources.

Configuration

To configure the connection with your Microsoft SQL database follow these steps:

1

Create the source `.yaml` file within the `queries` folder if you haven't already

/queries/source.yml

2

Add the following code for your Microsoft SQL connection

type: mssql
details:
    user: string
    password: string
    database: string
    server: string
    pool: {
        max: number
        min: number
        idleTimeoutMillis: number
    }
    options: {
        encrypt: boolean
        trustServerCertificate: boolean
    }
3

Replace the details section with your info and save

4

Done, now you can test your connection

Attributes

  • User → The username for logging into the SQL Server. It identifies the account that will be used for authentication.
  • Password → The password associated with the user account for authentication purposes.
  • Database → The name of the database on the SQL Server that you want to access or manipulate.
  • Server → The name or IP address of the SQL Server instance you are connecting to.
  • Max → (Optional) he maximum number of connections allowed in the connection pool. This is the upper limit on the number of active connections your application can have to the SQL Server at any time.
  • Min → (Optional) The minimum number of connections to maintain in the pool. This ensures that a certain number of connections are always ready and available.
  • IdleTimeoutMillis → (Optional) The amount of time, in milliseconds, a connection can remain idle in the pool before being closed. This helps manage and free up unused connections efficiently.
  • Encrypt → (Optional) A boolean setting that determines whether the data sent between the client and SQL Server should be encrypted. This is crucial for securing sensitive data in transit.
  • TrustServerCertificate → (Optional) A boolean setting that, when true, indicates the client should trust the SQL Server’s certificate without validating it. This is important for connections where SSL encryption is used but the server’s certificate may not be verified by a known Certificate Authority (CA).

Test connection

To test the connection you can:

  1. Create a query .sql in the queries directory that points to a table of your new connection in the FROM clause. See the section SQL Syntax Basics to learn more.
  2. Use the command line to run latitude run query_file_name where query_file_name is the name of your .sql file. This will display the results in your terminal. See the section Running queries to learn more about how to query your data.