How to use the objection.knexSnakeCaseMappers function in objection

To help you get started, we’ve selected a few objection examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github strvcom / nodejs-open-knowledge / src / database / index.js View on Github external
'use strict'

const objection = require('objection')
// -- Knex/PG issue: https://github.com/tgriesser/knex/issues/927
const pg = require('pg')

pg.types.setTypeParser(20, 'text', parseInt)
pg.types.setTypeParser(1700, 'text', parseFloat)
// -- end --
const knexLib = require('knex')
const R = require('ramda')
const config = require('../config')
const knexEnvConfig = require('./knexfile')[config.env]

const knexConfig = R.mergeDeepWith({}, knexEnvConfig, objection.knexSnakeCaseMappers())
const knex = knexLib(knexConfig)

const Model = objection.Model
Model.knex(knex)
const transaction = objection.transaction

function connect() {
  // Knex does not have an explicit `.connect()` method so we issue a query and consider the
  // connection to be open once we get the response back.
  return knex.raw('select 1 + 1')
}

function close() {
  return knex.destroy()
}
github ditojs / dito / packages / server / src / app / Application.js View on Github external
setupKnex() {
    let { knex, log } = this.config
    if (knex?.client) {
      const snakeCaseOptions = knex.normalizeDbNames === true
        ? {}
        : knex.normalizeDbNames
      if (snakeCaseOptions) {
        knex = {
          ...knex,
          ...knexSnakeCaseMappers(snakeCaseOptions)
        }
      }
      this.knex = Knex(knex)
      if (log.sql) {
        this.setupKnexLogging()
      }
    }
  }
github smooth-code / bundle-analyzer / apps / server / src / services / pg.js View on Github external
export function connect() {
  if (!knexInstance) {
    knexInstance = knex({
      ...config.get('pg'),
      ...knexSnakeCaseMappers(),
    })
    Model.knex(knexInstance)
  }

  return knexInstance
}
github smooth-code / bundle-analyzer / apps / server / src / services / pg.js View on Github external
export function createKnex() {
  return knex({
    ...config.get('pg'),
    ...knexSnakeCaseMappers(),
  })
}