how to set knex connection ssl options when using

2019-08-09 08:30发布

How can I set my connection's ssl property to true when I'm using a connection string to initialize knex? Similarly how to set the debug to true? I would normally pass in a connection object but in this case I have to use a connection string from environment variables.

var database = {
    client: 'pg',
    connection: connstr //normally I would pass in the object below
    //connection: {
    //    "host": config.get('database_host'),
    //    "user": config.get('database_user'),
    //    "password": config.get('database_password'),
    //    "database": config.get('database_name'),
    //    "debug": config.get('database_debug'),
    //    "ssl":config.get('database_ssl')
    //}
};

var knex = require('knex')(database);
knex.connection.ssl = true;  // this doesn't seem to do anything

标签: knex.js
1条回答
冷血范
2楼-- · 2019-08-09 08:49

Simply add ?ssl=true to the end of your connection string (at the end of the database name). For debug, either append ?debug=true after setting ssl or &debug=true I'm actually not sure sorry so just try both.

查看更多
登录 后发表回答