Yes you can use Microsoft SQL Server with Sails.js! I've done it on a few projects. Really all you need to do is add it to your config/connections.js file:
sqlserver: {
adapter: 'sails-sqlserver',
user: 'your_user',
password: 'your_pw',
host: 'host ip',
database: 'your_db_name',
// I've had to use this option in some cases
// where the SQL Server refuses my user otherwise
options: {
encrypt: false
}
},
Then use it the same way, by either defining it in your global config as default connection:
connection: 'sqlserver'
Or within a specific model:
// Define an adapter to use
adapter: 'sails-sqlserver'
You also might want to consider disabling some of the fields in the models like:
autoCreatedAt: false,
autoUpdatedAt: false,
And maybe enable migrate: 'safe' in the configs/models.js file.
As a side note, when I've had to do stored procedures from Node.js with a MS SQL server, I usually just fall back to using the mssql library directly.
3条答案
按热度按时间chy5wohz1#
Yes you can use Microsoft SQL Server with Sails.js! I've done it on a few projects. Really all you need to do is add it to your
config/connections.js
file:Then use it the same way, by either defining it in your global config as default connection:
Or within a specific model:
You also might want to consider disabling some of the fields in the models like:
And maybe enable
migrate: 'safe'
in theconfigs/models.js
file.As a side note, when I've had to do stored procedures from Node.js with a MS SQL server, I usually just fall back to using the
mssql
library directly.yebdmbv42#
I have similar problem with Sql server express as I added following to connections.js
},
the host definition is wierd but came from a post on Git
my sql express has tcp/ip enabled
but I get this sails startup error: ** the hook 'orm' takes to long to load**
now this database i can reach from asp.net MVC with following connection string
8dtrkrch3#
If you use latest version of Sails.js (currently it is 1.5.8) you will need to:
Mentioned below configuration may not work due to waterline package used by sails-hook-orm as it require url property to be defined.
and modify your config/models.js