-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: do not serialize empty hasMany relationships fix: n:m queries not executing correctly
- Loading branch information
1 parent
93e3c0a
commit 2d0f2ef
Showing
13 changed files
with
317 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,5 @@ test/* | |
node_modules/* | ||
|
||
# misc | ||
decl/* | ||
examples/* | ||
interfaces/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
declare class Proxy<T> { | ||
constructor(target: T, handler: { | ||
get?: (target: T, key: string, reciever: Proxy) => ?mixed | void; | ||
set?: (target: T, key: string, value: mixed, receiver: Proxy) => void; | ||
has?: (target: T, key: string) => boolean; | ||
}): T; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
// @flow | ||
import { worker, isMaster } from 'cluster'; | ||
|
||
import { MigrationsPendingError } from './errors'; | ||
|
||
import connect from './utils/connect'; | ||
import createMigrations from './utils/create-migrations'; | ||
import pendingMigrations from './utils/pending-migrations'; | ||
|
||
import type Database from './index'; | ||
import type Logger from '../logger'; | ||
import typeof Model from './model'; | ||
|
||
const { env: { NODE_ENV = 'development' } } = process; | ||
|
||
/** | ||
* @private | ||
*/ | ||
export default async function initialize(instance: Database, { | ||
path, | ||
models, | ||
config, | ||
logger, | ||
checkMigrations | ||
}: { | ||
path: string, | ||
models: Map<string, Model>, | ||
config: Object, | ||
logger: Logger, | ||
checkMigrations: boolean | ||
}): Promise<Database> { | ||
config = config[NODE_ENV]; | ||
|
||
const { | ||
debug = (NODE_ENV === 'development') | ||
}: { | ||
debug: boolean | ||
} = config; | ||
|
||
Object.defineProperties(instance, { | ||
path: { | ||
value: path, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}, | ||
|
||
debug: { | ||
value: debug, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}, | ||
|
||
models: { | ||
value: models, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}, | ||
|
||
logger: { | ||
value: logger, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}, | ||
|
||
config: { | ||
value: config, | ||
writable: false, | ||
enumerable: true, | ||
configurable: false | ||
}, | ||
|
||
schema: { | ||
value: () => instance.connection.schema, | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
}, | ||
|
||
connection: { | ||
value: connect(path, config), | ||
writable: false, | ||
enumerable: false, | ||
configurable: false | ||
} | ||
}); | ||
|
||
if (isMaster || worker && worker.id === 1) { | ||
await createMigrations(instance.schema); | ||
|
||
if (checkMigrations) { | ||
const pending = await pendingMigrations(path, () => { | ||
return instance.connection('migrations'); | ||
}); | ||
|
||
if (pending.length) { | ||
throw new MigrationsPendingError(pending); | ||
} | ||
} | ||
} | ||
|
||
await Promise.all( | ||
Array | ||
.from(models.values()) | ||
.map(model => { | ||
return model.initialize(instance, () => { | ||
return instance.connection(model.tableName); | ||
}); | ||
}) | ||
); | ||
|
||
return instance; | ||
} |
Oops, something went wrong.