cloudsqlmssql SQL dialect (Google Cloud SQL for SQL Server).cloudsqlmssqlcloudsqlmssqlmssql (tedious)CloudSQLMSSQLDialect extendsMSSQLDialect. It changes only two things:sqlserver user cannot run.| Property | Value |
|---|---|
| Dialect name | cloudsqlmssql |
| Extends | MSSQLDialect |
| Driver | mssql (tedious ≥ 16) |
| Optional SDK | @google-cloud/cloud-sql-connector |
| Default port | 1433 |
| Cloud SDK | @google-cloud/cloud-sql-connector (connector only) |
| Local runtime | none — hosted service only |
$ npm install ts-prorm-orm mssql$ pnpm add ts-prorm-orm mssql$ yarn add ts-prorm-orm mssql$ bun add ts-prorm-orm mssqlmssql is the same driver the mssql dialect uses. Add @google-cloud/cloud-sql-connector only for the token-based logins under Managed and cloud variants.import { Prorm } from 'ts-prorm-orm';
export const db = new Prorm({
dialect: 'cloudsqlmssql',
database: 'app',
username: 'sqlserver',
password: process.env.DB_PASSWORD,
dialectOptions: {
cloudSql: { instanceConnectionName: 'my-project:us-central1:my-instance' },
},
});import { DataTypes } from 'ts-prorm-orm';
const User = db.define('User', {
id: { type: DataTypes.INTEGER(), primaryKey: true, autoIncrement: true },
email: { type: DataTypes.STRING(255), allowNull: false, unique: true },
name: { type: DataTypes.STRING(100) },
});
await db.sync(); // CREATE TABLE — see Generated SQL belowimport { Op } from 'ts-prorm-orm';
await User.create({ email: 'ada@example.com', name: 'Ada' });
const page = await User.findAll({
where: { name: { [Op.like]: 'A%' } },
order: [['id', 'ASC']],
limit: 20,
offset: 40,
});import { Prorm } from 'ts-prorm-orm';
export const db = new Prorm({
dialect: 'cloudsqlmssql',
database: 'app',
username: 'sqlserver',
password: process.env.DB_PASSWORD,
dialectOptions: {
cloudSql: {
instanceConnectionName: 'my-project:us-central1:my-instance',
ipType: 'PRIVATE', // 'PUBLIC' (default) | 'PRIVATE' | 'PSC'
},
},
});@google-cloud/cloud-sql-connector installed next to the driver.import { Prorm } from 'ts-prorm-orm';
import * as fs from 'fs';
export const db = new Prorm({
dialect: 'cloudsqlmssql',
host: '10.0.0.5',
database: 'app',
username: 'sqlserver',
password: process.env.DB_PASSWORD,
dialectOptions: {
cloudSql: {
mode: 'direct',
instanceConnectionName: 'my-project:us-central1:my-instance',
serverCa: fs.readFileSync('server-ca.pem', 'utf8'),
},
},
});query(), captured with the driver stubbed out. The model layer inlines the values.db.sync() for the model in the Quick start:CREATE TABLEawait User.create({ email: 'ada@example.com', name: 'Ada' });
await User.update({ name: 'Grace' }, { where: { email: 'ada@example.com' } });
await User.destroy({ where: { id: 1 } });await User.upsert({ id: 1, email: 'ada@example.com', name: 'Ada Lovelace' });MERGE statementupsert() also reads the row by primary key before and after the write, to return the instance.await User.findAll({
where: { name: { [Op.like]: 'A%' } },
order: [['id', 'ASC']],
limit: 20,
offset: 40,
});await db.transaction(async (t) => {
await User.create({ email: 'grace@example.com', name: 'Grace' }, { transaction: t });
// A nested transaction is a SAVEPOINT; its failure undoes only its own work.
await db
.transaction(async (sp) => {
await User.destroy({ where: { id: 1 }, transaction: sp });
throw new Error('keep the row');
}, { transaction: t })
.catch(() => {});
});READPAST)lock with skipLocked inside a transaction:await db.transaction(async (t) => {
await User.findAll({ where: { name: 'Ada' }, lock: { level: 'UPDATE', skipLocked: true }, transaction: t });
});STRING → NVARCHAR(255), auto-increment INTEGER → INT, BOOLEAN → BIT, DATE → DATETIME2, UUID → UNIQUEIDENTIFIER, JSON → NVARCHAR(MAX). The type comparison lines the major engines up side by side.Cloud SQL for SQL Server supports IAM authentication for instance and
backup operations only. IAM authentication isn't supported for database
operations.
getTediousOptionsENOIAM ("Tedious does not support Auto IAM DB Authentication"), andcloudSqlConnectorOptions('tedious', { iam: true }) refuses thecloudSql.iam,cloudSql.tokenProvider and cloudSql.googleAuth when it is constructed, andusername / password: the built-in sqlserverCREATE LOGIN.const db = new Prorm({
dialect: 'cloudsqlmssql',
database: 'app',
username: 'sqlserver',
password: process.env.DB_PASSWORD,
dialectOptions: {
cloudSql: { instanceConnectionName: 'my-project:us-central1:my-instance', ipType: 'PRIVATE' },
},
});connect(). It gives tedious twoconnector (a function that opens an mTLS tunnel socket) andencrypt: false, which the dialect merges into options. TDS then runsserver and port. The connector isdisconnect() or when connecting fails.import * as fs from 'fs';
const db = new Prorm({
dialect: 'cloudsqlmssql',
host: '1a23b4cd5e67.1a2b345c6d27.us-central1.sql.goog',
database: 'app',
username: 'sqlserver',
password: process.env.DB_PASSWORD,
dialectOptions: {
cloudSql: {
serverCa: fs.readFileSync('server-ca.pem', 'utf8'), // gcloud sql ssl server-ca-certs list --format='value(cert)' --instance=I
serverName: '1a23b4cd5e67.1a2b345c6d27.us-central1.sql.goog', // DNS name in the certificate's SAN
},
},
});serverCa, the dialect sets these tedious options:encrypt: true and trustServerCertificate: false;cryptoCredentialsDetails.ca, set to the CA you pass;serverName, when you give one.serverName or else host, andclientCert/clientKey are refused.serverCa, the base dialect's TLS settings apply unchanged:encrypt: true, and trustServerCertificate: true unless you set it.sysadmin. The sqlserver user belongs to CustomerDbRootRole.max degree of parallelism,cost threshold for parallelism, user connections and the supported tracequery() checks every statement before sendingCloudSqlUnsupportedError:| Statement | Instead |
|---|---|
sp_configure '<option>', <value>, RECONFIGURE | Database flags: gcloud sql instances patch INSTANCE --database-flags=NAME=VALUE, or the console. sp_configure with no value, to read options, is allowed |
ALTER SERVER CONFIGURATION | Instance settings in the console / gcloud sql instances patch |
DBCC TRACEON / TRACEOFF | Trace flags (1204, 1222, 3226, 4199, …) as database flags |
RESTORE ... | gcloud sql import bak INSTANCE gs://BUCKET/FILE.bak --database=DB, or console Import; instance backups: gcloud sql backups restore |
SHUTDOWN | gcloud sql instances restart / patch, or the console |
CREATE/ALTER ASSEMBLY | Not available (no CLR) |
CREATE/ALTER ENDPOINT | Not available; connectivity is instance configuration |
CREATE/ALTER TRIGGER ... ON ALL SERVER | A database-level DDL trigger (ON DATABASE) |
ALTER SERVER ROLE sysadmin ADD MEMBER | Grant the specific permissions or database roles |
CloudSQLMSSQLDialect extends MSSQLDialect (mssql) andObject.getOwnPropertyNames(CloudSQLMSSQLDialect.prototype),| Area | Overridden |
|---|---|
| Connection and execution | connect, disconnect, query, resolvePoolConfig |
| Introspection | assertSupported |
capabilitiesOf() (src/transaction-support.ts),whereSupportOf() (src/query-builders/expression-render.ts),sqlObjectCapabilitiesOf() (src/sql-objects/capabilities.ts) and the| Capability | cloudsqlmssql |
|---|---|
| Transactions atomic | yes |
| Savepoints | yes (no explicit RELEASE) |
| Isolation | up to SERIALIZABLE; native levels SNAPSHOT |
| Transaction modes | read-only no; deferrable no; constraint deferral no |
| RETURNING | OUTPUT INSERTED.… on INSERT |
| Upsert | MERGE INTO … WHEN MATCHED / WHEN NOT MATCHED |
| JSON column | NVARCHAR(MAX) (JSONB → NVARCHAR(MAX)) |
| Vector column | VECTOR(3) |
| Array column | NVARCHAR(255) |
| WHERE builder | 18 operator keys; $and/$or/$not; $exists: no; $in subquery: no; expression operands: no |
| SQL objects | family mssql: triggers yes; procedures yes; functions multiStatement; materialized views emulated (indexedView); sequences yes; enums check; RLS no |
| Streaming | queryStream() present; LISTEN absent; createExtension() present |
tests/dialects/cloudsqlmssql.test.ts exercises the dialect with a mocked driver, so nothing touches a server.