使用连接字符串时如何设置knex connection ssl选项 [英] how to set knex connection ssl options when using a connection string

查看:92
本文介绍了使用连接字符串时如何设置knex connection ssl选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用连接字符串初始化knex时,如何将连接的ssl属性设置为true?同样,如何将调试设置为true?我通常会传入连接对象,但在这种情况下,我必须使用环境变量中的连接字符串.

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

推荐答案

只需将?ssl=true添加到连接字符串的末尾(数据库名称的末尾).为了进行调试,请在设置ssl后追加?debug=true&debug=true,我实际上不确定,因此请尝试两者.

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.

这篇关于使用连接字符串时如何设置knex connection ssl选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆