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

Support Database Schemas #153

Closed
jerfowler opened this issue Mar 27, 2018 · 0 comments
Closed

Support Database Schemas #153

jerfowler opened this issue Mar 27, 2018 · 0 comments

Comments

@jerfowler
Copy link
Contributor

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?

jerfowler added a commit to jerfowler/feathers-knex that referenced this issue Mar 27, 2018
@daffl daffl closed this as completed in ade8941 Apr 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant