-
Notifications
You must be signed in to change notification settings - Fork 75
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
remove slonik, insert postgres.js #564
Changes from all commits
932d273
75a9498
1326460
0169e55
eedfd26
4f4a2e7
dfcef3d
240ca85
ce225b5
2c63809
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// Copyright 2022 ODK Central Developers | ||
// See the NOTICE file at the top-level directory of this distribution and at | ||
// https://github.com/getodk/central-backend/blob/master/NOTICE. | ||
// This file is part of ODK Central. It is subject to the license terms in | ||
// the LICENSE file found in the top-level directory of this distribution and at | ||
// https://www.apache.org/licenses/LICENSE-2.0. No part of ODK Central, | ||
// including this file, may be copied, modified, propagated, or distributed | ||
// except according to the terms contained in the LICENSE file. | ||
|
||
// CRCRCR uhhhh confusing naming maybe idk | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm |
||
const _postgres = require('postgres'); | ||
const { connectionString } = require('../util/db'); | ||
|
||
const options = { | ||
// when saving to the database we transform all undefined to null rather than | ||
// throw. this ought to be safe at time of writing because it's exactly what | ||
// we did with slonik. possibly someday with better hygiene this can go away. | ||
transform: { undefined: null }, | ||
types: { | ||
// the functions here are how postgres implements them for numerics. | ||
// the issue is just that for range safety reasons they do not include | ||
// bigint in their default impl, which is a problem we are unlikely to have. | ||
// the practical problem is that count() in postgres yields a bigint. | ||
bigint: { to: 0, from: [ 20 ], serialize: (x => '' + x), parse: (x => +x) }, | ||
|
||
// we don't want to automatically assume all non-true values can be safely | ||
// equal to 'f', since we can take user input here. | ||
boolean: { | ||
to: 16, from: 16, | ||
serialize: (x => (x === true ? 't' : x === false ? 'f' : x)), | ||
parse: (x => x === 't') | ||
} | ||
} | ||
}; | ||
const postgres = (config) => _postgres(connectionString(config), options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure, but I think we'll need to do something more here to support SSL connections, which we currently support. From a quick glance, it looks like Slonik and postgres.js accept SSL options differently. For Slonik, we pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. #433 is about Slonik, but I think has some relevant discussion. |
||
|
||
// turns out you can get the templater just by omitting connection info completely. | ||
// and p/postgres is happy to mix template literals across "connections". | ||
const sql = _postgres(undefined, options); | ||
|
||
module.exports = { postgres, sql, options }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rm options |
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
//