Skip to content

Support Database Schemas #153

Closed
Closed

Description

@jerfowler

Steps to reproduce

feathers-knex doesn't support database schemas (MSSQL, PostgreSQL, SQLight3?)

So, this doesn't work:

module.exports = function (schemaName) {
  return context => {
    const { table, createQuery } = context.service;
    const knex = createQuery(context.params);

    // do something with query here
    knex.clearSelect().withSchema(schemaName).table(`${table} as ${table}`);

    context.params.knex = knex;
    return context;
  };
};

Actually, it would be super helpful to be able to specify the schema when passing in the options to the service:

app.use('/messages', service({
  Model: db,
  name: 'messages',
  schema: 'public'
}));

Fun fact: you can mimic schema behavior with SQLight3 with separate attached database files:

const knex = require('knex');

const db = knex({
  client: 'sqlite3',
  connection: {
    filename: './db.sqlite'
  }
});

// Create a public database
const schemaName = 'public';
knex({
  client: 'sqlite3',
  connection: {
    filename: `./${schemaName}.sqlite`
  }
});

// Attach the public database to mimic a "schema"
db.schema.raw(`attach database '${schemaName}.sqlite' as ${schemaName}`);

I've already got most of it done, so be on the lookout for a pull request!

Expected behavior

Support databases schemas (withSchema knex method)

Actual behavior

Errors... lots and lots of errors.

System configuration

Tell us about the applicable parts of your setup.

Module versions (especially the part that's not working):
latest
NodeJS version:
v8.10.0
Operating System:
Windows, yeah... I know.
Browser Version:
Chrome, of course... duh!
React Native Version:
N/A
Module Loader:
Say what now?

Activity

  1. added a commit that references this issue on Mar 27, 2018
    666cb40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions