Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

knex: rename connection object #1364

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/model/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ NODE_CONFIG_DIR=../../config DEBUG=knex:query,knex:bindings npx knex migrate:up
*/

const config = require('config');
const { connectionObject } = require('../util/db');
const { knexConnection } = require('../util/db');

module.exports = {
client: 'pg',
connection: connectionObject(config.get('default.database'))
connection: knexConnection(config.get('default.database'))
};

4 changes: 2 additions & 2 deletions lib/model/migrate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
// top-level operations with a database, like migrations.

const knex = require('knex');
const { connectionObject } = require('../util/db');
const { knexConnection } = require('../util/db');

// Connects to the postgres database specified in configuration and returns it.
const connect = (config) => knex({ client: 'pg', connection: connectionObject(config) });
const connect = (config) => knex({ client: 'pg', connection: knexConnection(config) });

// Connects to a database, passes it to a function for operations, then ensures its closure.
const withDatabase = (config) => (mutator) => {
Expand Down
4 changes: 2 additions & 2 deletions lib/util/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ const connectionString = (config) => {
};

// Returns an object that Knex will use to connect to the database.
const connectionObject = (config) => {
const knexConnection = (config) => {
const problem = validateConfig(config);
if (problem != null) throw problem;
// We ignore maximumPoolSize when using Knex.
Expand Down Expand Up @@ -588,7 +588,7 @@ const postgresErrorToProblem = (x) => {
};

module.exports = {
connectionString, connectionObject,
connectionString, knexConnection,
unjoiner, extender, sqlEquals, page, queryFuncs,
insert, insertMany, updater, markDeleted, markUndeleted,
QueryOptions,
Expand Down
18 changes: 9 additions & 9 deletions test/unit/util/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ describe('util/db', () => {
});
});

describe('connectionObject', () => {
const { connectionObject } = util;
describe('knexConnection', () => {
const { knexConnection } = util;

it('should return an object with the required options', () => {
const result = connectionObject({
const result = knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -116,7 +116,7 @@ describe('util/db', () => {
});

it('should include the port if one is specified', () => {
const result = connectionObject({
const result = knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -133,7 +133,7 @@ describe('util/db', () => {
});

it('should return the correct object if ssl is true', () => {
const result = connectionObject({
const result = knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -150,7 +150,7 @@ describe('util/db', () => {
});

it('should throw if ssl is false', () => {
const result = () => connectionObject({
const result = () => knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -161,7 +161,7 @@ describe('util/db', () => {
});

it('should throw if ssl is an object', () => {
const result = () => connectionObject({
const result = () => knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -172,7 +172,7 @@ describe('util/db', () => {
});

it('should allow (but ignore) maximumPoolSize', () => {
const result = connectionObject({
const result = knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand All @@ -188,7 +188,7 @@ describe('util/db', () => {
});

it('should throw for an unsupported option', () => {
const result = () => connectionObject({
const result = () => knexConnection({
host: 'localhost',
database: 'foo',
user: 'bar',
Expand Down
Loading