We are using sequelize package to connect to mssql server. Our backend code is in javascript.
We have a working code like below:
const sequelize = new Sequelize({
logging:log,
dialect:'mssql',
dialectModulePath: 'msnodesqlv8/lib/sequelize'
dialectOptions:{
connectionString: process.env.connectionString,
encrypt: false
},
operatorAliases: false
})
Below is the format of connectionString we are using in above snippet:
Driver={ODBC Driver 17 for SQL Server}; Server=<<Servername>>;Database=<<Database>>;Trusted_Connection=yes;
And in package.json I can see below 3 packages:
"msnodesqlv8":"^2.4.7",
"sequelize":"^4.41.2",
"sequelize-msnodesqlv8":"^0.2.6-beta.8"
In official doc of sequelize, I can see
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect:'mssql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
storage: 'path/to/database.sqlite'
});
There is no mention about msnodesqlv8. Right now connection is working fine. But I was just trying to understand if sequelize uses tedious under the hood in order to have appropriate drivers so that connection to DB can be made. Then what is the use of msnodesqlv8?
In msnodesqlv8 official docs I can see it has some enhanced security features.
What I am trying to achieve by understanding this?
I want to remove the dependency of my code from msnodesqlv8 and snippet provided in official document of sequelize for mssql is not working for me.
Reason for removing dependency of msnodesqlv8?
We are migrating code to linux and msnodesqlv8 is compatible with linux which has dependency on msodbcsql17 driver which needs to be installed separately.
After going to the pain of switching to the msnodesqlv8 driver today, I felt like I should comment on this... unfortunately my rep isn't high enough to comment so you get an answer instead :)
You're correct, many people seem to be using the msnodesqlv8 driver for the integrated security aspects.
I does have a dependency on msodbcsql17 (be sure not to try msodbcsql18). And this dependency is a pain to get in place. Word of warning.. trying to use it in a debian based docker image results in segfaults. We switched to alpine based and the segfaults cleared up.
What I haven't seen mentioned anywhere is the significant performance improvement you get from using msnodesqlv8. Small example, we have a simple query (takes .3 seconds to execute and another .3 to return 29000 <1kb rows using the JDBC driver) that would take 58 seconds using tedious. That was using tedious directly (not through sequelize or mssql for node). Almost all of that time was it reading the result stream. Switching to msnodesqlv8 reduced the time to under 2 seconds.
Summary: Pain to install. Much better performance for some workloads.
Related
I'm supporting a legacy Meteor 1.2.1 application using MongoDB Atlas and without any apparent code changes, it is suddenly not showing any documents - The code has not been changed for at least 5 months.
Looking in the DB, the documents are there, but on the server side, the find().fetch() calls are all returning 0 documents:
var documents = Articles.find().fetch();
console.log(`++ Found: ${documents.length} articles`);
logs:
++ Found: 0 articles
Interestingly, if I grab hold of the raw DB connection that Meteor is using and do a query myself, the data is found:
var getDocumentCounts = function (collectionName) {
var Future = Npm.require('fibers/future'), future = new Future();
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.collection(collectionName).count(
function(error, results) {
if (error) throw new Meteor.Error(500, "failed");
future.return(results);
}
);
return future.wait();
}
var result = getDocumentCounts('articles');
console.log(`articles: ${result}`);
logs:
articles: 259
The application is using some NPM packages, but is using an npm-shrinkwrap.json (legacy again) to ensure the versions of them are not accidentally upgraded during a restart/rebuild.
Node is from the Jurassic era # v0.10.41
I can't think why the application would suddenly develop this problem. Looking for a simple solution rather than the longwinded "upgrade everything"
Also interestingly, if I connect to my local dev mongo db, everything works fine. The MongDB Atlas is using shards whereas the local mongo is not, but it has had those shards for many many months.
My best opinion is that the problem is being caused by the fact that the mongo driver used by your Meteor version is no longer compatible with the mongo version running in Atlas. Check the Atlas MongoDB version, if possible.
I have 2 database servers. One for dev and one for production, what I want to do is to create a dumb of production DB and sync it with dev DB at a specific time using nodejs.
Postgres provides pg_dump (single DB) and pg_dumpall (all DBs) utilities out of the box. The simplest way would probably be a cron job to automate the backup of your source DB and scp it over to a destination server, then restore the DB on the destination server by a cron job:
On the source server:
crontab -e
0 0 * * 0 pg_dumpall -U postgres > ~/backups/backup.bak
# scp to your destination server
If you’re working in one of the major cloud environments they will have their own tools that can help, eg AWS you can automate snapshots, then restore from a snapshot (or have a lambda perform the restore from the snapshot as you suggest in nodeJs)
Or (super-cool way) is to use AWS DMS (Data Migration Services) CDC - Change Data Capture and you can replicate a source DB instantaneously with one or many target replicas (avoiding the need for dumps and restores)
I asume you meant dump, and googled that for you:
https://www.joseverissimo.com/blog/automatically-export-a-database-and-import-it-to-another-using-node-js
Now you just should make sure it runs as a cronjob.
Hello guys Im beginner in Sequelize and Node js,
I have read their offical docs, read their github, searched blog post and couldnt solve it.
Im constantly getting warning messages :
GMT sequelize deprecated String based operators are now deprecated. Please use Symbol based operators for better security, read more at http://docs.sequelizejs.com/manual/tutorial/querying.html#operators at node_modules/sequelize/lib/sequelize.js:236:13
This error is only happening when running migrations but this is not happening when Im starting server normally
Herei is my connection.js file
https://pastebin.com/5NKfExib
So I googled for few days and here is the answer:
operator alliases must be set to false when connecting to database like this:
sequelize = new Sequelize(config.database, config.username, config.password, Object.assign({}, config, {
pool: dbConst.pool,
operatorsAliases: false,
})
Also in migrations.config.json, operatorAliases must be set to false
And in your code always use Sequalize.Op
I am studying the MEAN stack by using this tutorial. But the tutorial connects to a remote mongodb installation. I have MongoDB running in the CentOS7 localhost.
How do I alter the mongoose connect line in server.js from the tutorial link above to connect to a localhost database instead of a remote database?
Here is the current line from server.js that needs to be changed to point to the localhost mongodb:
mongoose.connect('mongodb://node:nodeuser#mongo.onmodulus.net:27017/uwO3mypu');
A specific mongodb database has not been created yet. Do I need to create that also?
I'm fairly new at Mongo to, but I know how to connect to a local db. Basically I had to do the following:
Download the latest version of mongodb from https://www.mongodb.com/download-center?jmp=nav#community (according to your settings)
Once installed, I've created a folder that will be containing my DB.
Use a command line instance to start mongo like this:
mongod --dbpath [YOUR_DB_PATH]
Created a DB use mydb
With that you should have already a mongodb db instance looking for connections on default port. So you can change that line for this:
mongoose.connect('mongodb://localhost:27017/mydb');
Again, this is really basic and it is creating a mongo DB connection with all default options. So this will keep you rolling, but you may need to dig a bit more for custom options.
Hope this helps
I need to create a simple database for use in an Angular/Node demo. What is the path of least resistance to adding such a database to my demo?
Incidentally, I cannot use the MEAN stack.
Edit: I failed to mention that I'm running the demo from my local environment--from my laptop.
The path of least resistance would be to use Sequelize and sqlite3 in your application.
Start off by running npm install sequelize sqlite3.
Then in your code
var Sequelize = require( 'sequelize' )
var connection = Sequelize.connect( undefined, {
dialect: 'sqlite',
storage: __dirname + '/db.sqlite'
})
Tada, you have a database connection syncing to a local sqlite DB.
You'll likely need to consult the Sequelize documentation to use this connection.
If, however, you wanted an API for your angular demo, json-server is what you're looking for.