@tstdl/base 0.93.41 → 0.93.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/orm/sqls.d.ts CHANGED
@@ -60,7 +60,7 @@ export type TsHeadlineOptions = {
60
60
  fragmentDelimiter?: string;
61
61
  };
62
62
  export declare function enumValue<T extends EnumerationObject>(enumeration: T, value: EnumerationValue<T>): SQL<string>;
63
- export declare function singleReferenceCheck<E extends EnumerationObject>(enumeration: E, discriminator: Column, columns: Column[], columnMapping: Record<EnumerationValue<E>, Column>): SQL;
63
+ export declare function singleReferenceCheck<E extends EnumerationObject>(enumeration: E, discriminator: Column, columns: Column[], columnMapping: Record<EnumerationValue<E>, Column | null>): SQL;
64
64
  export declare function array<T>(values: SQL<T>[]): SQL<T[]>;
65
65
  export declare function array<T = unknown>(values: SQLChunk[]): SQL<T[]>;
66
66
  export declare function autoAlias<T>(column: AnyColumn<{
package/orm/sqls.js CHANGED
@@ -1,4 +1,5 @@
1
- import { assertDefined, isDefined, isNumber, isString } from '../utils/type-guards.js';
1
+ import { objectEntries } from '../utils/object/object.js';
2
+ import { assertDefined, isDefined, isNotNull, isNumber, isString } from '../utils/type-guards.js';
2
3
  import { and, eq, sql, Table } from 'drizzle-orm';
3
4
  import { getEnumName } from './enums.js';
4
5
  /** Drizzle SQL helper for getting the current transaction's timestamp. Returns a Date object. */
@@ -14,15 +15,15 @@ export function enumValue(enumeration, value) {
14
15
  }
15
16
  export function singleReferenceCheck(enumeration, discriminator, columns, columnMapping) {
16
17
  const whens = [];
17
- for (const [value, column] of Object.entries(columnMapping)) {
18
- whens.push(sql ` WHEN ${enumValue(enumeration, value)} THEN ${column} IS NOT NULL`);
18
+ for (const [value, column] of objectEntries(columnMapping)) {
19
+ if (isNotNull(column)) {
20
+ whens.push(sql ` WHEN ${enumValue(enumeration, value)} THEN ${column} IS NOT NULL`);
21
+ }
19
22
  }
20
- return and(sql `
21
- CASE ${discriminator}
23
+ return and(sql `CASE ${discriminator}
22
24
  ${sql.join(whens, sql `\n`)}
23
25
  ELSE FALSE
24
- END
25
- `, eq(numNonNulls(...columns), sql.raw('1')));
26
+ END`, eq(numNonNulls(...columns), sql.raw('1')));
26
27
  }
27
28
  export function array(values) {
28
29
  const valueString = sql.join(values, sql.raw(', '));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.41",
3
+ "version": "0.93.42",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"