You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To connect to a database, use .connect. You can pass a URL string where the scheme is a supported driver or you can pass an Object with the parameters of the connection.
varorm=require("orm");orm.connect("mysql://root:password@localhost/test",function(err,db){if(err){console.log("Something is wrong with the connection",err);return;}// connected!});
The callback is only called when the connection is done successfully (or unsuccessfully). You can avoid passing a callback and listen for the connect event if you prefer.
varorm=require("orm");vardb=orm.connect("mysql://root:password@localhost/test");orm.on("connect",function(err){if(err){console.log("Something is wrong with the connection",err);return;}// connected!});
The connection URL has the following syntax: driver://username:password@hostname/database?option1=value1&option2=value2..
Valid options are:
debug (default: false): prints queries to console;
pool (default: false): manages a connection pool (only for mysql and postgres) using built-in driver pool;
strdates (default: false): saves dates as strings (only for sqlite).