Skip to content

Commit

Permalink
fix: database is undefined when using the postgresql driver (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
zacharygolba authored Jan 4, 2017
1 parent 46ed68b commit f828e8e
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
17 changes: 8 additions & 9 deletions src/packages/cli/commands/dbcreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { createLoader } from '../../loader';
*/
export async function dbcreate() {
const load = createLoader(CWD);
let cfg = load('config');

cfg = Reflect.get(cfg.database, NODE_ENV);

const {
database: {
[NODE_ENV]: {
driver,
database,
url,
...config
}
}
} = load('config');
url,
driver,
database,
...config
} = cfg;

if (driver === 'sqlite3') {
await writeFile(`${CWD}/db/${database}_${NODE_ENV}.sqlite`, '');
Expand Down
17 changes: 8 additions & 9 deletions src/packages/cli/commands/dbdrop.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ import { createLoader } from '../../loader';
*/
export async function dbdrop() {
const load = createLoader(CWD);
let cfg = load('config');

cfg = Reflect.get(cfg.database, NODE_ENV);

const {
database: {
[NODE_ENV]: {
driver,
database,
url,
...config
}
}
} = load('config');
url,
driver,
database,
...config
} = cfg;

if (driver === 'sqlite3') {
await rmrf(`${CWD}/db/${database}_${NODE_ENV}.sqlite`);
Expand Down
11 changes: 5 additions & 6 deletions src/packages/cli/commands/dbseed.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,20 @@ import { createLoader } from '../../loader';
/**
* @private
*/
export async function dbseed() {
export function dbseed() {
const load = createLoader(CWD);

const { database: config } = load('config');
const seed = load('seed');
const models = load('models');

const store = await new Database({
return new Database({
config,
models,
path: CWD,
logger: new Logger({
enabled: false
})
});

await store.connection.transaction(seed);
}).then(store => (
store.connection.transaction(seed)
));
}
5 changes: 1 addition & 4 deletions src/packages/database/utils/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ export default function connect(path: string, config: Object = {}): Knex {
};
}

const knex: Class<Knex> = Reflect.apply(require, null, [
joinPath(path, 'node_modules', 'knex')
]);

const knex: Class<Knex> = require(joinPath(path, 'node_modules', 'knex'));
const usingSQLite = driver === 'sqlite3';

const connection = DATABASE_URL || url || {
Expand Down

0 comments on commit f828e8e

Please sign in to comment.