You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The function should allow passing the schema directly instead, or treating any first String argument as a glob, essentially being backward compatible with current implementation.
Implementation
exportfunctioncreateSqlmancerClient<TextendsGenericSqlmancerClient=GenericSqlmancerClient>(schema: string|object,knex: Knex): T{// load schema from glob patternif(typeofschema=== 'string') {
const glob = schema;
const typeDefs = getTypeDefsFromGlob(glob)
if (!typeDefs || !typeDefs.definitions.length) {
throw new Error(`Found no files with valid type definitions using glob pattern "${glob}"`)
}
schema = makeSqlmancerSchema({ typeDefs })
}
const { dialect, models } = getSqlmancerConfig(schema)
return Object.assign(knex, {
models: _.mapValues(models, (model: Model) => {
const options = { knex, dialect }
const { builders, readOnly } = model
return {
findById: (id: ID) => new builders.findById(options, id),
findMany: () => new builders.findMany(options),
findOne: () => new builders.findOne(options),
paginate: () => new builders.paginate(options),
createOne: readOnly ? undefined : (input: any) => new builders.createOne!(options, input),
createMany: readOnly ? undefined : (input: Array<any>) => new builders.createMany!(options, input),
deleteById: readOnly ? undefined : (id: ID) => new builders.deleteById!(options, id),
deleteMany: readOnly ? undefined : () => new builders.deleteMany!(options),
updateById: readOnly ? undefined : (id: ID, input: any) => new builders.updateById!(options, id, input),
updateMany: readOnly ? undefined : (input: any) => new builders.updateMany!(options, input),
}
}),
}) as any
}
The text was updated successfully, but these errors were encountered:
The current implementation currently requires loading the schema and definitions twice
The function should allow passing the
schema
directly instead, or treating any firstString
argument as a glob, essentially being backward compatible with current implementation.Implementation
The text was updated successfully, but these errors were encountered: