Skip to content

Commit

Permalink
Changed implementation of LOCK option to unprefix Table instead of re…
Browse files Browse the repository at this point in the history
…lying on new BareTable type
  • Loading branch information
jawj committed May 24, 2022
1 parent 7b93393 commit a8337d1
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
7 changes: 6 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-unused-vars": [
"warn",
{
"varsIgnorePattern": "^_"
}
],
"@typescript-eslint/await-thenable": "error",
"@typescript-eslint/no-floating-promises": "error",
"@typescript-eslint/member-delimiter-style": [
Expand Down
2 changes: 1 addition & 1 deletion src/db/canary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ Released under the MIT licence: see LICENCE file
* generated schema format, in order to raise a type error and thereby force
* schema regeneration.
*/
export interface SchemaVersionCanary { version: 105 }
export interface SchemaVersionCanary { version: 104 }
5 changes: 3 additions & 2 deletions src/db/shortcuts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import type {
Updatable,
Whereable,
Table,
BareTable,
Column,
} from 'zapatos/schema';

Expand Down Expand Up @@ -386,9 +385,11 @@ interface OrderSpecForTable<T extends Table> {
nulls?: 'FIRST' | 'LAST';
}

type Unprefixed<S extends string> = S extends `${infer _}.${infer Rest}` ? Rest : S;

export interface SelectLockingOptions<A extends string> {
for: 'UPDATE' | 'NO KEY UPDATE' | 'SHARE' | 'KEY SHARE';
of?: BareTable | A | (BareTable | A)[];
of?: Unprefixed<Table> | A | (Unprefixed<Table> | A)[];
wait?: 'NOWAIT' | 'SKIP LOCKED';
}

Expand Down
3 changes: 0 additions & 3 deletions src/generate/tables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export const definitionForRelationInSchema = async (
tableDef = `${tableComment}
export namespace ${rel.name} {
export type Table = '${schemaPrefix}${rel.name}';
export type BareTable = '${rel.name}';
export interface Selectable {
${selectables.join('\n ')}
}
Expand Down Expand Up @@ -237,7 +236,6 @@ export const crossTableTypesForTables = (tables: Relation[]) => `${tables.length
'\n// `never` rather than `any` types would be more accurate in this no-tables case, but they stop `shortcuts.ts` compiling\n' : ''
}
export type Table = ${tableMappedUnion(tables, 'Table')};
export type BareTable = ${tableMappedUnion(tables, 'BareTable')};
export type Selectable = ${tableMappedUnion(tables, 'Selectable')};
export type JSONSelectable = ${tableMappedUnion(tables, 'JSONSelectable')};
export type Whereable = ${tableMappedUnion(tables, 'Whereable')};
Expand Down Expand Up @@ -268,7 +266,6 @@ const
export const crossSchemaTypesForSchemas = (schemas: string[]) => `
export type Schema = ${schemas.map(s => `'${s}'`).join(' | ')};
export type Table = ${schemaMappedUnion(schemas, 'Table')};
export type BareTable = ${schemaMappedUnion(schemas, 'BareTable')};
export type Selectable = ${schemaMappedUnion(schemas, 'Selectable')};
export type JSONSelectable = ${schemaMappedUnion(schemas, 'JSONSelectable')};
export type Whereable = ${schemaMappedUnion(schemas, 'Whereable')};
Expand Down
2 changes: 1 addition & 1 deletion src/generate/tsOutput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export interface CustomTypes {
}

const
canaryVersion: SchemaVersionCanary['version'] = 105,
canaryVersion: SchemaVersionCanary['version'] = 104,
versionCanary = `
// got a type error on schemaVersionCanary below? update by running \`npx zapatos\`
export interface schemaVersionCanary extends db.SchemaVersionCanary { version: ${canaryVersion} }
Expand Down
1 change: 0 additions & 1 deletion src/typings/zapatos/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ export interface Updatable { [k: string]: any }
export interface Whereable { [k: string]: any }
export interface Insertable { [k: string]: any }
export type Table = string;
export type BareTable = string;
export type Column = string;
export type JSONSelectableForTable<T extends Table> = { [k: string]: any };
export type SelectableForTable<T extends Table> = { [k: string]: any };
Expand Down

0 comments on commit a8337d1

Please sign in to comment.