{"id":15062578,"url":"https://github.com/loopbackio/loopback-connector-mssql","last_synced_at":"2025-08-20T01:32:08.860Z","repository":{"id":13440712,"uuid":"16129899","full_name":"loopbackio/loopback-connector-mssql","owner":"loopbackio","description":"LoopBack connector for Microsoft SQL Server","archived":false,"fork":false,"pushed_at":"2023-12-15T08:41:26.000Z","size":485,"stargazers_count":52,"open_issues_count":8,"forks_count":80,"subscribers_count":41,"default_branch":"master","last_synced_at":"2025-08-09T00:02:01.433Z","etag":null,"topics":["hacktoberfest","mssql","nodejs","sql"],"latest_commit_sha":null,"homepage":"http://loopback.io/doc/en/lb3/SQL-Server-connector.html","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/loopbackio.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2014-01-22T05:34:06.000Z","updated_at":"2023-06-08T20:24:28.000Z","dependencies_parsed_at":"2024-01-13T17:10:26.001Z","dependency_job_id":"b1fe1c49-a145-4e7e-b976-29a46c5c9608","html_url":"https://github.com/loopbackio/loopback-connector-mssql","commit_stats":null,"previous_names":["strongloop/loopback-connector-mssql"],"tags_count":40,"template":false,"template_full_name":null,"purl":"pkg:github/loopbackio/loopback-connector-mssql","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-mssql","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-mssql/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-mssql/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-mssql/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/loopbackio","download_url":"https://codeload.github.com/loopbackio/loopback-connector-mssql/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/loopbackio%2Floopback-connector-mssql/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271252409,"owners_count":24726910,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","mssql","nodejs","sql"],"created_at":"2024-09-24T23:43:14.804Z","updated_at":"2025-08-20T01:32:08.561Z","avatar_url":"https://github.com/loopbackio.png","language":"JavaScript","readme":"# loopback-connector-mssql\n\n[Microsoft SQL Server](https://www.microsoft.com/en-us/sql-server/default.aspx) is a relational database management system developed by Microsoft.\nThe `loopback-connector-mssql` module is the Microsoft SQL Server connector for the LoopBack framework.\n\n\u003cdiv class=\"gh-only\"\u003e\nFor more information, see \u003ca href=\"http://loopback.io/doc/en/lb3/SQL-Server-connector.html\"\u003eLoopBack documentation\u003c/a\u003e.\n\u003c/div\u003e\n\n## Installation\n\nIn your application root directory, enter:\n\n```shell\n$ npm install loopback-connector-mssql --save\n```\n\nThis will install the module from npm and add it as a dependency to the application's `package.json` file.\n\nIf you create a SQL Server data source using the data source generator as described below, you don't have to do this, since the generator will run `npm install` for you.\n\n## Creating a SQL Server data source\n\nUse the [Data source generator](http://loopback.io/doc/en/lb3/Data-source-generator.html) to add a SQL Server data source to your application.  \nThe generator will prompt for the database server hostname, port, and other settings\nrequired to connect to a SQL Server database.  It will also run the `npm install` command above for you.\n\nThe entry in the application's `/server/datasources.json` will look like this (for example):\n\n{% include code-caption.html content=\"/server/datasources.json\" %}\n```javascript\n\"sqlserverdb\": {\n    \"name\": \"sqlserverdb\",\n    \"connector\": \"mssql\",\n    \"host\": \"myhost\",\n    \"port\": 1234,\n    \"url\": \"mssql://username:password@dbhost/dbname\",\n    \"database\": \"mydb\",\n    \"password\": \"admin\",\n    \"user\": \"admin\",\n  }\n```\n\nEdit `datasources.json` to add other properties that enable you to connect the data source to a SQL Server database.\n\nTo connect to a SQL Server instance running in Azure, you must specify a qualified user name with hostname, and add the following to the data source declaration:\n\n```js\n\"options\": {\n   \"encrypt\": true\n   ...\n}\n```\n\n### Connector settings\n\nTo configure the data source to use your MS SQL Server database, edit `datasources.json` and add the following settings as appropriate.\nThe MSSQL connector uses [node-mssql](https://github.com/patriksimek/node-mssql) as the driver. For more information about configuration parameters,\nsee [node-mssql documentation](https://github.com/patriksimek/node-mssql#configuration-1).\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eProperty\u003c/th\u003e\n      \u003cth\u003eType\u003c/th\u003e\n      \u003cth\u003eDefault\u003c/th\u003e\n      \u003cth\u003eDescription\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e\n    \u003ctr\u003e\n      \u003ctd\u003econnector\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003e\n        Either \"loopback-connector-mssql\" or \"mssql\"\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003edatabase\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003eDatabase name\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003edebug\u003c/td\u003e\n      \u003ctd\u003eBoolean\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003eIf true, turn on verbose mode to debug database queries and lifecycle.\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ehost\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003elocalhost\u003c/td\u003e\n      \u003ctd\u003eDatabase host name\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003epassword\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003ePassword to connect to database\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eport\u003c/td\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n      \u003ctd\u003e1433\u003c/td\u003e\n      \u003ctd\u003eDatabase TCP port\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eschema\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003edbo\u003c/td\u003e\n      \u003ctd\u003eDatabase schema\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eurl\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003eUse instead of the \u003ccode\u003ehost\u003c/code\u003e, \u003ccode\u003eport\u003c/code\u003e, \u003ccode\u003euser\u003c/code\u003e, \u003ccode\u003epassword\u003c/code\u003e,\n        and \u003ccode\u003edatabase\u003c/code\u003e properties.  For example: 'mssql://test:mypassword@localhost:1433/dev'.\n      \u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003euser\u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n      \u003ctd\u003e \u003c/td\u003e\n      \u003ctd\u003eQualified username with host name, for example \"user@your.sqlserver.dns.host\".\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\nInstead of specifying individual connection properties, you can use a single `url` property that combines them into a single string, for example:\n\n```javascript\n\"accountDB\": {\n    \"url\": \"mssql://test:mypassword@localhost:1433/demo?schema=dbo\"\n}\n```\n\nThe application will automatically load the data source when it starts. You can then refer to it in code, for example:\n\n{% include code-caption.html content=\"/server/boot/script.js\" %}\n```javascript\nvar app = require('./app');\nvar dataSource = app.dataSources.accountDB;\n```\n\nAlternatively, you can create the data source in application code; for example:\n\n{% include code-caption.html content=\"/server/script.js\" %}\n```javascript\nvar DataSource = require('loopback-datasource-juggler').DataSource;\nvar dataSource = new DataSource('mssql', config);\nconfig = { ... };  // JSON object as specified above in \"Connector settings\"\n```\n\n\n### Model discovery\n\nThe SQL Server connector supports _model discovery_ that enables you to create LoopBack models\nbased on an existing database schema using the unified [database discovery API](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-discoverandbuildmodels).  For more information on discovery, see [Discovering models from relational databases](https://loopback.io/doc/en/lb3/Discovering-models-from-relational-databases.html).\n\n### Auto-migratiion\n\nThe SQL Server connector also supports _auto-migration_ that enables you to create a database schema\nfrom LoopBack models using the [LoopBack automigrate method](http://apidocs.strongloop.com/loopback-datasource-juggler/#datasource-prototype-automigrate).\nFor each model, the LoopBack SQL Server connector creates a table in the 'dbo' schema in the database.\n\nFor more information on auto-migration, see [Creating a database schema from models](https://loopback.io/doc/en/lb3/Creating-a-database-schema-from-models.html) for more information.\n\nDestroying models may result in errors due to foreign key integrity. First delete any related models by calling delete on models with relationships.\n\n## Defining models\n\nThe model definition consists of the following properties:\n\n* `name`: Name of the model, by default, the table name in camel-case.\n* `options`: Model-level operations and mapping to Microsoft SQL Server schema/table. Use the `mssql` model property to specify additional SQL Server-specific properties for a LoopBack model.\n* `properties`: Property definitions, including mapping to Microsoft SQL Server columns.\n  - For each property, use the `mssql` key to specify additional settings for that property/field.\n\nFor example:\n\n{% include code-caption.html content=\"/common/models/inventory.json\" %}\n```javascript\n{\"name\": \"Inventory\", \n     \"options\": {\n       \"idInjection\": false,\n       \"mssql\": {\n         \"schema\": \"strongloop\",\n         \"table\": \"inventory\"\n       }\n     }, \"properties\": {\n      \"id\": {\n        \"type\": \"String\",\n        \"required\": false,\n        \"length\": 64,\n        \"precision\": null,\n        \"scale\": null,\n        \"mssql\": {\n          \"columnName\": \"id\",\n          \"dataType\": \"varchar\",\n          \"dataLength\": 64,\n          \"dataPrecision\": null,\n          \"dataScale\": null,\n          \"nullable\": \"NO\"\n        }\n      },\n      \"productId\": {\n        \"type\": \"String\",\n        \"required\": false,\n        \"length\": 64,\n        \"precision\": null,\n        \"scale\": null,\n        \"id\": 1,\n        \"mssql\": {\n          \"columnName\": \"product_id\",\n          \"dataType\": \"varchar\",\n          \"dataLength\": 64,\n          \"dataPrecision\": null,\n          \"dataScale\": null,\n          \"nullable\": \"YES\"\n        }\n      },\n      \"locationId\": {\n        \"type\": \"String\",\n        \"required\": false,\n        \"length\": 64,\n        \"precision\": null,\n        \"scale\": null,\n        \"id\": 1,\n        \"mssql\": {\n          \"columnName\": \"location_id\",\n          \"dataType\": \"varchar\",\n          \"dataLength\": 64,\n          \"dataPrecision\": null,\n          \"dataScale\": null,\n          \"nullable\": \"YES\"\n        }\n      },\n      \"available\": {\n        \"type\": \"Number\",\n        \"required\": false,\n        \"length\": null,\n        \"precision\": 10,\n        \"scale\": 0,\n        \"mssql\": {\n          \"columnName\": \"available\",\n          \"dataType\": \"int\",\n          \"dataLength\": null,\n          \"dataPrecision\": 10,\n          \"dataScale\": 0,\n          \"nullable\": \"YES\"\n        }\n      },\n      \"total\": {\n        \"type\": \"Number\",\n        \"required\": false,\n        \"length\": null,\n        \"precision\": 10,\n        \"scale\": 0,\n        \"mssql\": {\n          \"columnName\": \"total\",\n          \"dataType\": \"int\",\n          \"dataLength\": null,\n          \"dataPrecision\": 10,\n          \"dataScale\": 0,\n          \"nullable\": \"YES\"\n        }\n      }\n    }}\n```\n\n## Type mapping\n\nSee [LoopBack types](http://loopback.io/doc/en/lb3/LoopBack-types.html) for details on LoopBack's data types.\n\n### LoopBack to SQL Server types\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eLoopBack Type\u003c/th\u003e\n      \u003cth\u003eSQL Server Type\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e    \n    \u003ctr\u003e\n      \u003ctd\u003eBoolean\u003c/td\u003e\n      \u003ctd\u003eBIT\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eDate\u003c/td\u003e\n      \u003ctd\u003eDATETIME\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eGeoPoint\u003c/td\u003e\n      \u003ctd\u003eFLOAT\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n      \u003ctd\u003eINT\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        String\n        JSON\n      \u003c/td\u003e\n      \u003ctd\u003e\n        NVARCHAR\n      \u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n### SQL Server to LoopBack types\n\n\u003ctable\u003e\n  \u003cthead\u003e\n    \u003ctr\u003e\n      \u003cth\u003eSQL Server Type\u003c/th\u003e\n      \u003cth\u003eLoopBack Type\u003c/th\u003e\n    \u003c/tr\u003e\n  \u003c/thead\u003e\n  \u003ctbody\u003e    \n    \u003ctr\u003e\n      \u003ctd\u003eBIT\u003c/td\u003e\n      \u003ctd\u003eBoolean\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        BINARY\u003cbr\u003eVARBINARY\u003cbr\u003eIMAGE\n      \u003c/td\u003e\n      \u003ctd\u003eNode.js \u003ca class=\"external-link\" href=\"http://nodejs.org/api/buffer.html\" rel=\"nofollow\"\u003eBuffer object\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        DATE\u003cbr\u003eDATETIMEOFFSET\u003cbr\u003eDATETIME2\u003cbr\u003eSMALLDATETIME\u003cbr\u003eDATETIME\u003cbr\u003eTIME\n      \u003c/td\u003e\n      \u003ctd\u003eDate\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003ePOINT\u003c/td\u003e\n      \u003ctd\u003e\u003ca href=\"http://apidocs.strongloop.com/loopback-datasource-juggler/#geopoint\"\u003eGeoPoint\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        BIGINT\u003cbr\u003eNUMERIC\u003cbr\u003eSMALLINT\u003cbr\u003eDECIMAL\u003cbr\u003eSMALLMONEY\u003cbr\u003eINT\u003cbr\u003eTINYINT\u003cbr\u003eMONEY\u003cbr\u003eFLOAT\u003cbr\u003eREAL\n      \u003c/td\u003e\n      \u003ctd\u003eNumber\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n      \u003ctd\u003e\n        CHAR\u003cbr\u003eVARCHAR\u003cbr\u003eTEXT\u003cbr\u003eNCHAR\u003cbr\u003eNVARCHAR\u003cbr\u003eNTEXT\u003cbr\u003eCHARACTER VARYING\u003cbr\u003eCHARACTER\n      \u003c/td\u003e\n      \u003ctd\u003eString\u003c/td\u003e\n    \u003c/tr\u003e\n  \u003c/tbody\u003e\n\u003c/table\u003e\n\n## Running tests\n\n### Own instance\nIf you have a local or remote MSSQL instance and would like to use that to run the test suite, use the following command:\n- Linux\n```bash\nMSSQL_HOST=\u003cHOST\u003e MSSQL_PORT=\u003cPORT\u003e MSSQL_USER=\u003cUSER\u003e MSSQL_PASSWORD=\u003cPASSWORD\u003e MSSQL_DATABASE=\u003cDATABASE\u003e CI=true npm test\n```\n- Windows\n```bash\nSET MSSQL_HOST=\u003cHOST\u003e SET MSSQL_PORT=\u003cPORT\u003e SET MSSQL_USER=\u003cUSER\u003e SET MSSQL_PASSWORD=\u003cPASSWORD\u003e SET MSSQL_DATABASE=\u003cDATABASE\u003e SET CI=true npm test\n```\n\n### Docker\nIf you do not have a local MSSQL instance, you can also run the test suite with very minimal requirements.\n- Assuming you have [Docker](https://docs.docker.com/engine/installation/) installed, run the following script which would spawn a MSSQL instance on your local:\n```bash\nsource setup.sh \u003cHOST\u003e \u003cPORT\u003e \u003cUSER\u003e \u003cPASSWORD\u003e \u003cDATABASE\u003e\n```\nwhere `\u003cHOST\u003e`, `\u003cPORT\u003e`, `\u003cUSER\u003e`, `\u003cPASSWORD\u003e` and `\u003cDATABASE\u003e` are optional parameters. The default values are `localhost`, `1433`, `sa`, `M55sqlT35t` and `master` respectively.\n- Run the test:\n```bash\nnpm test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-mssql","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Floopbackio%2Floopback-connector-mssql","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Floopbackio%2Floopback-connector-mssql/lists"}