pqb 0.42.7 → 0.42.9
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/dist/index.d.ts +162 -4
- package/dist/index.js +187 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -48
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -2689,6 +2689,7 @@ declare class JSONTextColumn<Schema extends ColumnSchemaConfig> extends ColumnTy
|
|
|
2689
2689
|
interface TableData {
|
|
2690
2690
|
primaryKey?: TableData.PrimaryKey;
|
|
2691
2691
|
indexes?: TableData.Index[];
|
|
2692
|
+
excludes?: TableData.Exclude[];
|
|
2692
2693
|
constraints?: TableData.Constraint[];
|
|
2693
2694
|
}
|
|
2694
2695
|
declare namespace TableData {
|
|
@@ -2701,11 +2702,19 @@ declare namespace TableData {
|
|
|
2701
2702
|
options: Index.ColumnArg & Index.Options;
|
|
2702
2703
|
name?: string;
|
|
2703
2704
|
}
|
|
2705
|
+
export interface ColumnExclude extends ColumnIndex {
|
|
2706
|
+
with: string;
|
|
2707
|
+
}
|
|
2704
2708
|
export interface Index {
|
|
2705
2709
|
columns: Index.ColumnOrExpressionOptions[];
|
|
2706
2710
|
options: Index.Options;
|
|
2707
2711
|
name?: string;
|
|
2708
2712
|
}
|
|
2713
|
+
export interface Exclude {
|
|
2714
|
+
columns: Exclude.ColumnOrExpressionOptions[];
|
|
2715
|
+
options: Exclude.Options;
|
|
2716
|
+
name?: string;
|
|
2717
|
+
}
|
|
2709
2718
|
export interface Constraint {
|
|
2710
2719
|
name?: string;
|
|
2711
2720
|
check?: Check;
|
|
@@ -2751,7 +2760,7 @@ declare namespace TableData {
|
|
|
2751
2760
|
with?: string;
|
|
2752
2761
|
tablespace?: string;
|
|
2753
2762
|
where?: string;
|
|
2754
|
-
dropMode?:
|
|
2763
|
+
dropMode?: DropMode;
|
|
2755
2764
|
}
|
|
2756
2765
|
export interface OptionsArg extends UniqueOptionsArg {
|
|
2757
2766
|
unique?: boolean;
|
|
@@ -2781,6 +2790,34 @@ declare namespace TableData {
|
|
|
2781
2790
|
export type ColumnOrExpressionOptions<Column extends PropertyKey = string> = ColumnOptionsForColumn<Column> | ExpressionOptions;
|
|
2782
2791
|
export { };
|
|
2783
2792
|
}
|
|
2793
|
+
export namespace Exclude {
|
|
2794
|
+
export interface Options {
|
|
2795
|
+
using?: string;
|
|
2796
|
+
include?: MaybeArray<string>;
|
|
2797
|
+
with?: string;
|
|
2798
|
+
tablespace?: string;
|
|
2799
|
+
where?: string;
|
|
2800
|
+
dropMode?: DropMode;
|
|
2801
|
+
}
|
|
2802
|
+
export interface ArgColumnOptions {
|
|
2803
|
+
collate?: string;
|
|
2804
|
+
opclass?: string;
|
|
2805
|
+
order?: string;
|
|
2806
|
+
}
|
|
2807
|
+
export interface ColumnArg extends Options, ArgColumnOptions {
|
|
2808
|
+
}
|
|
2809
|
+
interface ColumnBaseOptions extends ArgColumnOptions {
|
|
2810
|
+
with: string;
|
|
2811
|
+
}
|
|
2812
|
+
interface ColumnOptions<Column extends PropertyKey> extends ColumnBaseOptions {
|
|
2813
|
+
column: Column;
|
|
2814
|
+
}
|
|
2815
|
+
interface ExpressionOptions extends ColumnBaseOptions {
|
|
2816
|
+
expression: string;
|
|
2817
|
+
}
|
|
2818
|
+
export type ColumnOrExpressionOptions<Column extends PropertyKey = string> = ColumnOptions<Column> | ExpressionOptions;
|
|
2819
|
+
export { };
|
|
2820
|
+
}
|
|
2784
2821
|
export namespace References {
|
|
2785
2822
|
type FnOrTable = (() => ForeignKeyTable) | string;
|
|
2786
2823
|
/**
|
|
@@ -2811,6 +2848,7 @@ declare namespace TableData {
|
|
|
2811
2848
|
type TableDataInput = {
|
|
2812
2849
|
primaryKey?: TableData.PrimaryKey;
|
|
2813
2850
|
index?: TableData.Index;
|
|
2851
|
+
exclude?: TableData.Exclude;
|
|
2814
2852
|
constraint?: TableData.Constraint;
|
|
2815
2853
|
};
|
|
2816
2854
|
interface TableDataItem {
|
|
@@ -2842,6 +2880,76 @@ interface TableDataMethods<Key extends PropertyKey> {
|
|
|
2842
2880
|
};
|
|
2843
2881
|
index(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.OptionsArg] | [name?: string, options?: TableData.Index.OptionsArg]): NonUniqDataItem;
|
|
2844
2882
|
searchIndex(columns: (Key | TableData.Index.ColumnOrExpressionOptions<Key>)[], ...args: [options?: TableData.Index.TsVectorArg] | [name?: string, options?: TableData.Index.TsVectorArg]): NonUniqDataItem;
|
|
2883
|
+
/**
|
|
2884
|
+
* Defines an `EXCLUDE` constraint for multiple columns.
|
|
2885
|
+
*
|
|
2886
|
+
* The first argument is an array of columns and/or SQL expressions:
|
|
2887
|
+
*
|
|
2888
|
+
* ```ts
|
|
2889
|
+
* interface ExcludeColumnOptions {
|
|
2890
|
+
* // column name OR expression is required
|
|
2891
|
+
* column: string;
|
|
2892
|
+
* // SQL expression, like 'tstzrange("startDate", "endDate")'
|
|
2893
|
+
* expression: string;
|
|
2894
|
+
*
|
|
2895
|
+
* // required: operator for the EXCLUDE constraint to work
|
|
2896
|
+
* with: string;
|
|
2897
|
+
*
|
|
2898
|
+
* collate?: string;
|
|
2899
|
+
* opclass?: string; // for example, varchar_ops
|
|
2900
|
+
* order?: string; // ASC, DESC, ASC NULLS FIRST, DESC NULLS LAST
|
|
2901
|
+
* }
|
|
2902
|
+
* ```
|
|
2903
|
+
*
|
|
2904
|
+
* The second argument is an optional object with options for the whole exclude constraint:
|
|
2905
|
+
*
|
|
2906
|
+
* ```ts
|
|
2907
|
+
* interface ExcludeOptions {
|
|
2908
|
+
* // algorithm to use such as GIST, GIN
|
|
2909
|
+
* using?: string;
|
|
2910
|
+
* // EXCLUDE creates an index under the hood, include columns to the index
|
|
2911
|
+
* include?: MaybeArray<string>;
|
|
2912
|
+
* // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
|
|
2913
|
+
* with?: string;
|
|
2914
|
+
* // The tablespace in which to create the constraint. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
|
|
2915
|
+
* tablespace?: string;
|
|
2916
|
+
* // WHERE clause to filter records for the constraint
|
|
2917
|
+
* where?: string;
|
|
2918
|
+
* // for dropping the index at a down migration
|
|
2919
|
+
* dropMode?: DropMode;
|
|
2920
|
+
* }
|
|
2921
|
+
* ```
|
|
2922
|
+
*
|
|
2923
|
+
* Example:
|
|
2924
|
+
*
|
|
2925
|
+
* ```ts
|
|
2926
|
+
* import { change } from '../dbScript';
|
|
2927
|
+
*
|
|
2928
|
+
* change(async (db) => {
|
|
2929
|
+
* await db.createTable(
|
|
2930
|
+
* 'table',
|
|
2931
|
+
* (t) => ({
|
|
2932
|
+
* id: t.identity().primaryKey(),
|
|
2933
|
+
* roomId: t.integer(),
|
|
2934
|
+
* startAt: t.timestamp(),
|
|
2935
|
+
* endAt: t.timestamp(),
|
|
2936
|
+
* }),
|
|
2937
|
+
* (t) => [
|
|
2938
|
+
* t.exclude(
|
|
2939
|
+
* [
|
|
2940
|
+
* { column: 'roomId', with: '=' },
|
|
2941
|
+
* { expression: 'tstzrange("startAt", "endAt")', with: '&&' },
|
|
2942
|
+
* ],
|
|
2943
|
+
* {
|
|
2944
|
+
* using: 'GIST',
|
|
2945
|
+
* },
|
|
2946
|
+
* ),
|
|
2947
|
+
* ],
|
|
2948
|
+
* );
|
|
2949
|
+
* });
|
|
2950
|
+
* ```
|
|
2951
|
+
*/
|
|
2952
|
+
exclude(columns: TableData.Exclude.ColumnOrExpressionOptions<Key>[], ...args: [options?: TableData.Exclude.Options] | [name?: string, options?: TableData.Exclude.Options]): NonUniqDataItem;
|
|
2845
2953
|
foreignKey<ForeignTable extends (() => ForeignKeyTable) | string, ForeignColumns extends ForeignTable extends () => ForeignKeyTable ? [
|
|
2846
2954
|
ColumnNameOfTable<ReturnType<ForeignTable>>,
|
|
2847
2955
|
...ColumnNameOfTable<ReturnType<ForeignTable>>[]
|
|
@@ -7828,6 +7936,7 @@ interface ColumnData extends ColumnDataBase {
|
|
|
7828
7936
|
dateTimePrecision?: number;
|
|
7829
7937
|
validationDefault?: unknown;
|
|
7830
7938
|
indexes?: TableData.ColumnIndex[];
|
|
7939
|
+
excludes?: TableData.ColumnExclude[];
|
|
7831
7940
|
comment?: string;
|
|
7832
7941
|
collate?: string;
|
|
7833
7942
|
compression?: string;
|
|
@@ -8117,6 +8226,52 @@ declare abstract class ColumnType<Schema extends ColumnTypeSchemaArg = ColumnTyp
|
|
|
8117
8226
|
dataType: string;
|
|
8118
8227
|
}>(this: T, ...args: [options?: TableData.Index.TsVectorColumnArg] | [name: string, options?: TableData.Index.TsVectorColumnArg]): T;
|
|
8119
8228
|
unique<T extends PickColumnData, Name extends string>(this: T, ...args: [options?: TableData.Index.UniqueColumnArg] | [name: Name, options?: TableData.Index.UniqueColumnArg]): UniqueColumn<T, Name>;
|
|
8229
|
+
/**
|
|
8230
|
+
* Add [EXCLUDE constraint](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE) to the column.
|
|
8231
|
+
*
|
|
8232
|
+
* ```ts
|
|
8233
|
+
* import { change } from '../dbScript';
|
|
8234
|
+
*
|
|
8235
|
+
* change(async (db) => {
|
|
8236
|
+
* await db.createTable('table', (t) => ({
|
|
8237
|
+
* // exclude rows with overlapping time ranges, && is for the `WITH` operator
|
|
8238
|
+
* timeRange: t.type('tstzrange').exclude('&&'),
|
|
8239
|
+
* // with a database-level name:
|
|
8240
|
+
* timeRange: t.type('tstzrange').exclude('&&', 'no_overlap'),
|
|
8241
|
+
* // with options:
|
|
8242
|
+
* timeRange: t.type('tstzrange').exclude('&&', { ...options }),
|
|
8243
|
+
* // with name and options:
|
|
8244
|
+
* name: t.type('tstzrange').exclude('&&', 'no_overlap', { ...options }),
|
|
8245
|
+
* }));
|
|
8246
|
+
* });
|
|
8247
|
+
* ```
|
|
8248
|
+
*
|
|
8249
|
+
* Possible options are:
|
|
8250
|
+
*
|
|
8251
|
+
* ```ts
|
|
8252
|
+
* interface ExcludeColumnOptions {
|
|
8253
|
+
* // specify collation:
|
|
8254
|
+
* collate?: string;
|
|
8255
|
+
* // see `opclass` in the Postgres document for creating the index
|
|
8256
|
+
* opclass?: string;
|
|
8257
|
+
* // specify index order such as ASC NULLS FIRST, DESC NULLS LAST
|
|
8258
|
+
* order?: string;
|
|
8259
|
+
* // algorithm to use such as GIST, GIN
|
|
8260
|
+
* using?: string;
|
|
8261
|
+
* // EXCLUDE creates an index under the hood, include columns to the index
|
|
8262
|
+
* include?: MaybeArray<string>;
|
|
8263
|
+
* // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
|
|
8264
|
+
* with?: string;
|
|
8265
|
+
* // The tablespace in which to create the constraint. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
|
|
8266
|
+
* tablespace?: string;
|
|
8267
|
+
* // WHERE clause to filter records for the constraint
|
|
8268
|
+
* where?: string;
|
|
8269
|
+
* // for dropping the index at a down migration
|
|
8270
|
+
* dropMode?: DropMode;
|
|
8271
|
+
* }
|
|
8272
|
+
* ```
|
|
8273
|
+
*/
|
|
8274
|
+
exclude<T extends PickColumnData>(this: T, ...args: [op: string, options?: TableData.Exclude.ColumnArg] | [op: string, name: string, options?: TableData.Exclude.ColumnArg]): T;
|
|
8120
8275
|
comment<T extends PickColumnData>(this: T, comment: string): T;
|
|
8121
8276
|
compression<T extends PickColumnData>(this: T, compression: string): T;
|
|
8122
8277
|
collate<T extends PickColumnData>(this: T, collate: string): T;
|
|
@@ -8298,14 +8453,17 @@ declare const isDefaultTimeStamp: (item: ColumnTypeBase) => boolean;
|
|
|
8298
8453
|
declare const columnsShapeToCode: (ctx: ColumnToCodeCtx, shape: ColumnsShapeBase) => Codes;
|
|
8299
8454
|
declare const pushTableDataCode: (code: Codes, ast: TableData) => Codes;
|
|
8300
8455
|
declare const primaryKeyInnerToCode: (primaryKey: TableData.PrimaryKey, t: string) => string;
|
|
8301
|
-
declare const indexToCode: (index: TableData.Index, t: string, prefix?: string) => Codes;
|
|
8302
8456
|
declare const indexInnerToCode: (index: TableData.Index, t: string) => Codes;
|
|
8457
|
+
declare const indexToCode: (item: TableData.Index, t: string, prefix?: string) => Codes;
|
|
8458
|
+
declare const excludeInnerToCode: (item: TableData.Exclude, t: string) => Codes;
|
|
8459
|
+
declare const excludeToCode: (item: TableData.Exclude, t: string, prefix?: string) => Codes;
|
|
8303
8460
|
declare const constraintToCode: (item: TableData.Constraint, t: string, m?: boolean, prefix?: string) => Codes;
|
|
8304
8461
|
declare const constraintInnerToCode: (item: TableData.Constraint, t: string, m?: boolean) => Codes;
|
|
8305
8462
|
declare const referencesArgsToCode: ({ columns, fnOrTable, foreignColumns, options, }: Exclude<TableData.Constraint['references'], undefined>, name?: string | false, m?: boolean) => Codes;
|
|
8306
8463
|
declare const columnForeignKeysToCode: (foreignKeys: TableData.ColumnReferences[], migration: boolean | undefined) => Codes;
|
|
8307
8464
|
declare const foreignKeyArgumentToCode: ({ fnOrTable, foreignColumns, options, }: TableData.ColumnReferences, migration: boolean | undefined) => Codes;
|
|
8308
|
-
declare const columnIndexesToCode: (
|
|
8465
|
+
declare const columnIndexesToCode: (items: Exclude<ColumnData['indexes'], undefined>) => Codes;
|
|
8466
|
+
declare const columnExcludesToCode: (items: Exclude<ColumnData['excludes'], undefined>) => Codes;
|
|
8309
8467
|
declare const columnCheckToCode: (ctx: ColumnToCodeCtx, { sql, name }: ColumnDataCheckBase, columnName: string) => string;
|
|
8310
8468
|
declare const identityToCode: (identity: TableData.Identity, dataType?: string) => Codes;
|
|
8311
8469
|
declare const columnCode: (type: ColumnType, ctx: ColumnToCodeCtx, key: string, code: Code) => Code;
|
|
@@ -8511,4 +8669,4 @@ type CopyResult<T extends PickQueryMeta> = SetQueryKind<T, 'copy'>;
|
|
|
8511
8669
|
*/
|
|
8512
8670
|
declare function copyTableData<T extends PickQueryMetaShape>(query: T, arg: CopyArg<T>): CopyResult<T>;
|
|
8513
8671
|
|
|
8514
|
-
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsTable, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOne, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsOneOptional, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL, toSQLCacheKey };
|
|
8672
|
+
export { Adapter, type AdapterConfig, type AdapterOptions, type AddQueryDefaults, AfterCommitError, type AfterCommitErrorFulfilledResult, type AfterCommitErrorRejectedResult, type AfterCommitErrorResult, type AfterHook, type AggregateArgTypes, AggregateMethods, type AggregateOptions, type AliasOrTable, ArrayColumn, type ArrayColumnValue, type ArrayData, AsMethods, type AsQueryArg, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, type BooleanQueryColumn, BoxColumn, ByteaColumn, type ChangeCountArg, CidrColumn, CircleColumn, CitextColumn, Clear, type ClearStatement, type ColumnData, type ColumnDataGenerated, type ColumnFromDbParams, type ColumnInfoQueryData, ColumnRefExpression, ColumnType, type ColumnsByType, type ColumnsShape, type ColumnsShapeToNullableObject, type ColumnsShapeToObject, type ColumnsShapeToObjectArray, type ColumnsShapeToPluck, type CommonQueryData, ComputedColumn, type ComputedColumns, type ComputedColumnsFromOptions, type ComputedMethods, type ComputedOptionsFactory, type CopyOptions, type CopyQueryData, Create, type CreateBelongsToData, type CreateColumn, type CreateCtx, type CreateData, type CreateKind, type CreateMethodsNames, type CreateRelationsData, type CreateRelationsDataOmittingFKeys, type CreateResult, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnInput, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbDomainArgRecord, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbTableConstructor, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultSchemaConfig, Delete, type DeleteArgs, type DeleteMethodsNames, type DeleteQueryData, type DeleteResult, DomainColumn, DoublePrecisionColumn, DynamicRawSQL, EnumColumn, ExpressionMethods, type ExpressionOutput, FnExpression, type FnExpressionArgs, type FnExpressionArgsPairs, type FnExpressionArgsValue, For, type FromArg, FromMethods, type FromQuerySelf, type FromResult, type GeneratorIgnore, type GetArg, type GetColumnInfo, type GetResult, type GetResultOptional, type GetStringArg, type GroupArgs, type HandleResult, Having, type HavingItem, type HookAction, type HookSelectArg, type IdentityColumn, InetColumn, type InsertQueryData, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsolationLevel, JSONColumn, JSONTextColumn, Join, type JoinArgToQuery, type JoinArgs, type JoinCallback, type JoinFirstArg, type JoinItem, type JoinItemArgs, type JoinLateralItem, type JoinLateralResult, type JoinQueryBuilder, type JoinQueryMethod, type JoinResult, type JoinedParsers, type JoinedShapes, JsonMethods, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MergeQuery, MergeQueryMethods, MoneyColumn, MoreThanOneRowError, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, type NumericColumns, type OnConflictMerge, OnConflictQueryBuilder, type OnConflictSet, type OnConflictTarget, OnMethods, type Operator, Operators, type OperatorsAny, type OperatorsArray, type OperatorsBoolean, type OperatorsDate, type OperatorsJson, type OperatorsNumber, type OperatorsText, type OperatorsTime, type OrCreateArg, OrExpression, OrchidOrmError, OrchidOrmInternalError, type OrderArg, type OrderArgSelf, type OrderArgs, type OrderItem, type OrderTsQueryConfig, type Over, PathColumn, type PickColumnData, type PickQueryBaseQuery, type PickQueryColumnTypes, type PickQueryDataShapeAndJoinedShapes, type PickQueryInternal, type PickQueryMetaRelations, type PickQueryMetaRelationsResult, type PickQueryMetaResultRelations, type PickQueryMetaResultRelationsWindows, type PickQueryMetaResultRelationsWindowsColumnTypes, type PickQueryMetaResultRelationsWithDataReturnType, type PickQueryMetaResultRelationsWithDataReturnTypeShape, type PickQueryMetaResultReturnTypeWithDataWindows, type PickQueryMetaResultReturnTypeWithDataWindowsTable, type PickQueryMetaShapeRelationsWithData, type PickQueryMetaTable, type PickQueryMetaTableShape, type PickQueryMetaTableShapeReturnTypeWithData, type PickQueryMetaWithData, type PickQueryMetaWithDataColumnTypes, type PickQueryQ, type PickQueryQAndBaseQuery, type PickQueryQAndInternal, type PickQueryRelations, type PickQueryRelationsWithData, type PickQueryResultColumnTypes, type PickQueryShapeResultSinglePrimaryKey, type PickQueryShapeSinglePrimaryKey, type PickQuerySinglePrimaryKey, type PickQueryWindows, type PickQueryWithData, type PickQueryWithDataColumnTypes, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type PostgisPoint, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBatchResult, type QueryBeforeHook, type QueryComputedArg, type QueryData, type QueryDataFromItem, type QueryDataJoinTo, type QueryDefaultReturnData, QueryError, type QueryErrorName, QueryGet, type QueryGetSelf, type QueryHelperResult, QueryHooks, type QueryInternal, QueryLog, type QueryMetaHasSelect, type QueryMetaHasWhere, QueryMethods, type QueryOrExpression, type QueryOrExpressionBooleanOrNullResult, type QueryResult, type QueryScopeData, type QueryScopes, type QuerySourceItem, QueryUpsertOrCreate, RawSQL, RealColumn, type RecordOfColumnsShapeBase, RefExpression, type RelationConfigBase, type RelationConfigDataForCreate, type RelationJoinQuery, type RelationQueryBase, type RelationsBase, type RuntimeComputedQueryColumn, type SearchArg, SearchMethods, type SearchWeight, type SearchWeightRecord, Select, type SelectArg, type SelectArgs, type SelectAs, type SelectAsValue, type SelectItem, type SelectQueryData, type SelectSubQueryResult, type SelectableFromShape, type SelectableOfType, type SelectableOrExpression, type SelectableOrExpressionOfType, type SelectableOrExpressions, SerialColumn, type SerialColumnData, type SetQueryKind, type SetQueryKindResult, type SetQueryReturnsAll, type SetQueryReturnsAllKind, type SetQueryReturnsAllKindResult, type SetQueryReturnsColumnInfo, type SetQueryReturnsColumnKind, type SetQueryReturnsColumnKindResult, type SetQueryReturnsColumnOptional, type SetQueryReturnsColumnOrThrow, type SetQueryReturnsOne, type SetQueryReturnsOneKind, type SetQueryReturnsOneKindResult, type SetQueryReturnsOneOptional, type SetQueryReturnsPluck, type SetQueryReturnsPluckColumn, type SetQueryReturnsPluckColumnKind, type SetQueryReturnsPluckColumnKindResult, type SetQueryReturnsRowCount, type SetQueryReturnsRowCountMany, type SetQueryReturnsRows, type SetQueryReturnsValueOptional, type SetQueryReturnsValueOrThrow, type SetQueryReturnsVoid, type SetQueryReturnsVoidKind, type SetQueryTableAlias, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SimpleJoinItem, type SimpleJoinItemNonSubQueryArgs, SmallIntColumn, SmallSerialColumn, type SortDir, type SqlFn, SqlMethod, StringColumn$1 as StringColumn, TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, TextBaseColumn, TextColumn, type TextColumnData, Then, TimeColumn, TimestampColumn, TimestampTZColumn, type ToSQLCtx, type ToSQLOptions, type ToSQLQuery, Transaction, TransactionAdapter, type TransactionOptions, TransformMethods, type TruncateQueryData, TsQueryColumn, TsVectorColumn, type TypeParsers, UUIDColumn, UnhandledTypeError, Union, type UnionArgs, type UnionItem, type UnionKind, type UnionSet, type UniqueConstraints, type UniqueQueryTypeOrExpression, type UniqueTableDataItem, UnknownColumn, Update, type UpdateArg, type UpdateCtx, type UpdateCtxCollect, type UpdateData, type UpdateQueryData, type UpdateQueryDataItem, type UpdateQueryDataObject, type UpdateSelf, type UpdatedAtDataInjector, type UpsertResult, type UpsertThis, VarCharColumn, VirtualColumn, Where, type WhereArg, type WhereArgs, type WhereInArg, type WhereInColumn, type WhereInItem, type WhereInValues, type WhereItem, type WhereJsonPathEqualsItem, type WhereNotArgs, type WhereOnItem, type WhereOnJoinItem, type WhereQueryBuilder, type WhereResult, type WhereSearchItem, type WhereSearchResult, type WindowArg, type WindowArgDeclaration, type WindowDeclaration, type WindowItem, type WithArgsOptions, type WithConfigs, type WithDataItem, type WithDataItems, type WithItem, WithMethods, type WithOptions, type WithQueryBuilder, type WithRecursiveOptions, type WithResult, type WithSqlResult, type WrapQueryArg, XMLColumn, _afterCommitError, _clone, _getSelectableColumn, _initQueryBuilder, _queryAfterSaveCommit, _queryAll, _queryAs, _queryChangeCounter, _queryCreate, _queryCreateFrom, _queryCreateMany, _queryCreateManyFrom, _queryCreateManyRaw, _queryCreateRaw, _queryDefaults, _queryDelete, _queryExec, _queryFindBy, _queryFindByOptional, _queryGet, _queryGetOptional, _queryHookAfterCreate, _queryHookAfterCreateCommit, _queryHookAfterDelete, _queryHookAfterDeleteCommit, _queryHookAfterQuery, _queryHookAfterSave, _queryHookAfterUpdate, _queryHookAfterUpdateCommit, _queryHookBeforeCreate, _queryHookBeforeDelete, _queryHookBeforeQuery, _queryHookBeforeSave, _queryHookBeforeUpdate, _queryInsert, _queryInsertFrom, _queryInsertMany, _queryInsertManyFrom, _queryInsertManyRaw, _queryInsertRaw, _queryJoinOn, _queryJoinOnJsonPathEquals, _queryJoinOrOn, _queryOr, _queryOrNot, _queryResolveAlias, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUnion, _queryUpdate, _queryUpdateOrThrow, _queryUpdateRaw, _queryWhere, _queryWhereExists, _queryWhereIn, _queryWhereNot, _queryWhereNotOneOf, _queryWhereNotSql, _queryWhereOneOf, _queryWhereSql, addColumnParserToQuery, addParserForRawExpression, addParserForSelectItem, addQueryOn, anyShape, applyComputedColumns, checkIfASimpleQuery, cloneQuery, cloneQueryBaseUnscoped, columnCheckToCode, columnCode, columnExcludesToCode, columnForeignKeysToCode, columnIndexesToCode, columnsShapeToCode, commitSql, constraintInnerToCode, constraintToCode, copyTableData, countSelect, createDb, defaultSchemaConfig, escapeForLog, escapeForMigration, escapeString, excludeInnerToCode, excludeToCode, extendQuery, filterResult, foreignKeyArgumentToCode, getClonedQueryData, getColumnInfo, getColumnTypes, getFullColumnTable, getPrimaryKeys, getQueryAs, getShapeFromSelect, getSqlText, handleResult, identityToCode, indexInnerToCode, indexToCode, instantiateColumn, isDefaultTimeStamp, isQueryReturnsAll, isSelectingCount, joinSubQuery, logParamToLogObject, makeColumnTypes, makeColumnsByType, makeFnExpression, makeRegexToFindInSql, makeSQL, parseRecord, parseTableData, parseTableDataInput, postgisTypmodToSql, primaryKeyInnerToCode, processComputedBatches, processComputedResult, processSelectArg, pushLimitSQL, pushQueryArray, pushQueryOn, pushQueryOnForOuter, pushQueryOrOn, pushQueryValue, pushTableDataCode, queryFrom, queryFromSql, queryJson, queryMethodByReturnType, queryTypeWithLimitOne, queryWrap, raw, referencesArgsToCode, resolveSubQueryCallback, rollbackSql, saveSearchAlias, setColumnDefaultParse, setColumnEncode, setColumnParse, setColumnParseNull, setParserForSelectedString, setQueryObjectValue, setQueryOperators, simplifyColumnDefault, sqlFn, sqlQueryArgsToExpression, tableDataMethods, templateLiteralToSQL, testTransaction, throwIfJoinLateral, throwIfNoWhere, toSQL, toSQLCacheKey };
|
package/dist/index.js
CHANGED
|
@@ -331,6 +331,58 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
331
331
|
name: typeof args[0] === "string" ? args[0] : void 0
|
|
332
332
|
});
|
|
333
333
|
}
|
|
334
|
+
/**
|
|
335
|
+
* Add [EXCLUDE constraint](https://www.postgresql.org/docs/current/sql-createtable.html#SQL-CREATETABLE-EXCLUDE) to the column.
|
|
336
|
+
*
|
|
337
|
+
* ```ts
|
|
338
|
+
* import { change } from '../dbScript';
|
|
339
|
+
*
|
|
340
|
+
* change(async (db) => {
|
|
341
|
+
* await db.createTable('table', (t) => ({
|
|
342
|
+
* // exclude rows with overlapping time ranges, && is for the `WITH` operator
|
|
343
|
+
* timeRange: t.type('tstzrange').exclude('&&'),
|
|
344
|
+
* // with a database-level name:
|
|
345
|
+
* timeRange: t.type('tstzrange').exclude('&&', 'no_overlap'),
|
|
346
|
+
* // with options:
|
|
347
|
+
* timeRange: t.type('tstzrange').exclude('&&', { ...options }),
|
|
348
|
+
* // with name and options:
|
|
349
|
+
* name: t.type('tstzrange').exclude('&&', 'no_overlap', { ...options }),
|
|
350
|
+
* }));
|
|
351
|
+
* });
|
|
352
|
+
* ```
|
|
353
|
+
*
|
|
354
|
+
* Possible options are:
|
|
355
|
+
*
|
|
356
|
+
* ```ts
|
|
357
|
+
* interface ExcludeColumnOptions {
|
|
358
|
+
* // specify collation:
|
|
359
|
+
* collate?: string;
|
|
360
|
+
* // see `opclass` in the Postgres document for creating the index
|
|
361
|
+
* opclass?: string;
|
|
362
|
+
* // specify index order such as ASC NULLS FIRST, DESC NULLS LAST
|
|
363
|
+
* order?: string;
|
|
364
|
+
* // algorithm to use such as GIST, GIN
|
|
365
|
+
* using?: string;
|
|
366
|
+
* // EXCLUDE creates an index under the hood, include columns to the index
|
|
367
|
+
* include?: MaybeArray<string>;
|
|
368
|
+
* // see "storage parameters" in the Postgres document for creating an index, for example, 'fillfactor = 70'
|
|
369
|
+
* with?: string;
|
|
370
|
+
* // The tablespace in which to create the constraint. If not specified, default_tablespace is consulted, or temp_tablespaces for indexes on temporary tables.
|
|
371
|
+
* tablespace?: string;
|
|
372
|
+
* // WHERE clause to filter records for the constraint
|
|
373
|
+
* where?: string;
|
|
374
|
+
* // for dropping the index at a down migration
|
|
375
|
+
* dropMode?: DropMode;
|
|
376
|
+
* }
|
|
377
|
+
* ```
|
|
378
|
+
*/
|
|
379
|
+
exclude(...args) {
|
|
380
|
+
return orchidCore.pushColumnData(this, "excludes", {
|
|
381
|
+
with: args[0],
|
|
382
|
+
options: (typeof args[1] === "string" ? args[2] : args[1]) ?? orchidCore.emptyObject,
|
|
383
|
+
name: typeof args[1] === "string" ? args[1] : void 0
|
|
384
|
+
});
|
|
385
|
+
}
|
|
334
386
|
comment(comment) {
|
|
335
387
|
return orchidCore.setColumnData(this, "comment", comment);
|
|
336
388
|
}
|
|
@@ -371,7 +423,7 @@ class ColumnType extends orchidCore.ColumnTypeBase {
|
|
|
371
423
|
toCode() {
|
|
372
424
|
let sql2 = ".generated";
|
|
373
425
|
if (Array.isArray(args[0])) {
|
|
374
|
-
sql2 += orchidCore.
|
|
426
|
+
sql2 += orchidCore.templateLiteralSQLToCode(args);
|
|
375
427
|
} else {
|
|
376
428
|
const { raw: raw2, values } = args[0];
|
|
377
429
|
sql2 += `({ raw: '${raw2.replace(/'/g, "\\'")}'${values ? `, values: ${JSON.stringify(values)}` : ""} })`;
|
|
@@ -455,20 +507,12 @@ const columnsShapeToCode = (ctx, shape) => {
|
|
|
455
507
|
return code;
|
|
456
508
|
};
|
|
457
509
|
const pushTableDataCode = (code, ast) => {
|
|
458
|
-
const lines = [
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
lines.push(indexToCode(index, "t"));
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
if (ast.constraints) {
|
|
468
|
-
for (const constraint of ast.constraints) {
|
|
469
|
-
lines.push(constraintToCode(constraint, "t", true));
|
|
470
|
-
}
|
|
471
|
-
}
|
|
510
|
+
const lines = [
|
|
511
|
+
ast.primaryKey && [primaryKeyInnerToCode(ast.primaryKey, "t") + ","],
|
|
512
|
+
...ast.indexes?.map((x) => indexToCode(x, "t")) || orchidCore.emptyArray,
|
|
513
|
+
...ast.excludes?.map((x) => excludeToCode(x, "t")) || orchidCore.emptyArray,
|
|
514
|
+
...ast.constraints?.map((x) => constraintToCode(x, "t", true)) || orchidCore.emptyArray
|
|
515
|
+
].filter((x) => !!x);
|
|
472
516
|
if (lines.length > 1) {
|
|
473
517
|
code.push("(t) => [", ...lines, "],");
|
|
474
518
|
} else if (lines[0].length === 1 && typeof lines[0][0] === "string") {
|
|
@@ -482,18 +526,17 @@ const primaryKeyInnerToCode = (primaryKey, t) => {
|
|
|
482
526
|
const name = primaryKey.name;
|
|
483
527
|
return `${t}.primaryKey([${primaryKey.columns.map(orchidCore.singleQuote).join(", ")}]${name ? `, ${orchidCore.singleQuote(name)}` : ""})`;
|
|
484
528
|
};
|
|
485
|
-
const
|
|
486
|
-
const code =
|
|
529
|
+
const indexOrExcludeToCode = (innerToCode) => (item, t, prefix) => {
|
|
530
|
+
const code = innerToCode(item, t);
|
|
487
531
|
if (prefix) code[0] = prefix + code[0];
|
|
488
532
|
const last = code[code.length - 1];
|
|
489
533
|
if (typeof last === "string" && !last.endsWith(",")) orchidCore.addCode(code, ",");
|
|
490
534
|
return code;
|
|
491
535
|
};
|
|
492
536
|
const indexInnerToCode = (index, t) => {
|
|
493
|
-
const code = [
|
|
494
|
-
code.push(
|
|
537
|
+
const code = [
|
|
495
538
|
`${t}.${index.options.tsVector ? "searchIndex" : index.options.unique ? "unique" : "index"}(`
|
|
496
|
-
|
|
539
|
+
];
|
|
497
540
|
const columnOptions = ["collate", "opclass", "order", "weight"];
|
|
498
541
|
const indexOptionsKeys = [
|
|
499
542
|
index.options.tsVector ? "unique" : void 0,
|
|
@@ -584,6 +627,54 @@ const indexInnerToCode = (index, t) => {
|
|
|
584
627
|
}
|
|
585
628
|
return code;
|
|
586
629
|
};
|
|
630
|
+
const indexToCode = indexOrExcludeToCode(indexInnerToCode);
|
|
631
|
+
const excludeInnerToCode = (item, t) => {
|
|
632
|
+
const code = [`${t}.exclude(`];
|
|
633
|
+
const columnOptions = ["collate", "opclass", "order", "with"];
|
|
634
|
+
const optionsKeys = [
|
|
635
|
+
"using",
|
|
636
|
+
"include",
|
|
637
|
+
"with",
|
|
638
|
+
"tablespace",
|
|
639
|
+
"where",
|
|
640
|
+
"dropMode"
|
|
641
|
+
];
|
|
642
|
+
const hasOptions = optionsKeys.some((key) => key && item.options[key]);
|
|
643
|
+
const objects = [];
|
|
644
|
+
for (const column of item.columns) {
|
|
645
|
+
const expr = "column" in column ? column.column : column.expression;
|
|
646
|
+
const props = [
|
|
647
|
+
`${"column" in column ? "column" : "expression"}: ${orchidCore.singleQuote(expr)},`
|
|
648
|
+
];
|
|
649
|
+
for (const key of columnOptions) {
|
|
650
|
+
const value = column[key];
|
|
651
|
+
if (value !== void 0) {
|
|
652
|
+
props.push(`${key}: ${orchidCore.singleQuote(value)},`);
|
|
653
|
+
}
|
|
654
|
+
}
|
|
655
|
+
objects.push("{", props, "},");
|
|
656
|
+
}
|
|
657
|
+
code.push(["[", objects, hasOptions || item.name ? "]," : "]"]);
|
|
658
|
+
if (item.name) {
|
|
659
|
+
orchidCore.addCode(code, ` ${orchidCore.singleQuote(item.name)},`);
|
|
660
|
+
}
|
|
661
|
+
if (hasOptions) {
|
|
662
|
+
code.push(["{"]);
|
|
663
|
+
const options = [];
|
|
664
|
+
for (const key of optionsKeys) {
|
|
665
|
+
if (!key) continue;
|
|
666
|
+
const value = item.options[key];
|
|
667
|
+
if (value === null || value === void 0) continue;
|
|
668
|
+
options.push(
|
|
669
|
+
`${key}: ${Array.isArray(value) ? orchidCore.singleQuoteArray(value) : typeof value === "string" ? orchidCore.singleQuote(value) : value},`
|
|
670
|
+
);
|
|
671
|
+
}
|
|
672
|
+
code.push([options, "},"]);
|
|
673
|
+
}
|
|
674
|
+
code.push("),");
|
|
675
|
+
return code;
|
|
676
|
+
};
|
|
677
|
+
const excludeToCode = indexOrExcludeToCode(excludeInnerToCode);
|
|
587
678
|
const constraintToCode = (item, t, m, prefix) => {
|
|
588
679
|
const code = constraintInnerToCode(item, t, m);
|
|
589
680
|
if (prefix) code[0] = prefix + code[0];
|
|
@@ -672,25 +763,22 @@ const foreignKeyArgumentToCode = ({
|
|
|
672
763
|
}
|
|
673
764
|
return code;
|
|
674
765
|
};
|
|
675
|
-
const columnIndexesToCode = (
|
|
766
|
+
const columnIndexesToCode = (items) => {
|
|
676
767
|
const code = [];
|
|
677
|
-
for (const { options, name } of
|
|
768
|
+
for (const { options, name } of items) {
|
|
678
769
|
orchidCore.addCode(code, `.${options.unique ? "unique" : "index"}(`);
|
|
679
|
-
const arr = [
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
)
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
if (options.tablespace)
|
|
692
|
-
arr.push(`tablespace: ${orchidCore.singleQuote(options.tablespace)},`);
|
|
693
|
-
if (options.where) arr.push(`where: ${orchidCore.singleQuote(options.where)},`);
|
|
770
|
+
const arr = [
|
|
771
|
+
options.collate && `collate: ${orchidCore.singleQuote(options.collate)},`,
|
|
772
|
+
options.opclass && `opclass: ${orchidCore.singleQuote(options.opclass)},`,
|
|
773
|
+
options.order && `order: ${orchidCore.singleQuote(options.order)},`,
|
|
774
|
+
name && `name: ${orchidCore.singleQuote(name)},`,
|
|
775
|
+
options.using && `using: ${orchidCore.singleQuote(options.using)},`,
|
|
776
|
+
options.include && `include: ${typeof options.include === "string" ? orchidCore.singleQuote(options.include) : `[${options.include.map(orchidCore.singleQuote).join(", ")}]`},`,
|
|
777
|
+
options.nullsNotDistinct && `nullsNotDistinct: true,`,
|
|
778
|
+
options.with && `with: ${orchidCore.singleQuote(options.with)},`,
|
|
779
|
+
options.tablespace && `tablespace: ${orchidCore.singleQuote(options.tablespace)},`,
|
|
780
|
+
options.where && `where: ${orchidCore.singleQuote(options.where)},`
|
|
781
|
+
].filter((x) => !!x);
|
|
694
782
|
if (arr.length) {
|
|
695
783
|
orchidCore.addCode(code, "{");
|
|
696
784
|
orchidCore.addCode(code, arr);
|
|
@@ -700,6 +788,30 @@ const columnIndexesToCode = (indexes) => {
|
|
|
700
788
|
}
|
|
701
789
|
return code;
|
|
702
790
|
};
|
|
791
|
+
const columnExcludesToCode = (items) => {
|
|
792
|
+
const code = [];
|
|
793
|
+
for (const { options, name, with: w } of items) {
|
|
794
|
+
orchidCore.addCode(code, `.exclude('${w}'`);
|
|
795
|
+
const arr = [
|
|
796
|
+
options.collate && `collate: ${orchidCore.singleQuote(options.collate)},`,
|
|
797
|
+
options.opclass && `opclass: ${orchidCore.singleQuote(options.opclass)},`,
|
|
798
|
+
options.order && `order: ${orchidCore.singleQuote(options.order)},`,
|
|
799
|
+
name && `name: ${orchidCore.singleQuote(name)},`,
|
|
800
|
+
options.using && `using: ${orchidCore.singleQuote(options.using)},`,
|
|
801
|
+
options.include && `include: ${typeof options.include === "string" ? orchidCore.singleQuote(options.include) : `[${options.include.map(orchidCore.singleQuote).join(", ")}]`},`,
|
|
802
|
+
options.with && `with: ${orchidCore.singleQuote(options.with)},`,
|
|
803
|
+
options.tablespace && `tablespace: ${orchidCore.singleQuote(options.tablespace)},`,
|
|
804
|
+
options.where && `where: ${orchidCore.singleQuote(options.where)},`
|
|
805
|
+
].filter((x) => !!x);
|
|
806
|
+
if (arr.length) {
|
|
807
|
+
orchidCore.addCode(code, ", {");
|
|
808
|
+
orchidCore.addCode(code, arr);
|
|
809
|
+
orchidCore.addCode(code, "}");
|
|
810
|
+
}
|
|
811
|
+
orchidCore.addCode(code, ")");
|
|
812
|
+
}
|
|
813
|
+
return code;
|
|
814
|
+
};
|
|
703
815
|
const columnCheckToCode = (ctx, { sql, name }, columnName) => {
|
|
704
816
|
return `.check(${sql.toCode(ctx.t)}${name && name !== `${ctx.table}_${columnName}_check` ? `, { name: '${name}' }` : ""})`;
|
|
705
817
|
};
|
|
@@ -779,6 +891,11 @@ const columnCode = (type, ctx, key, code) => {
|
|
|
779
891
|
orchidCore.addCode(code, part);
|
|
780
892
|
}
|
|
781
893
|
}
|
|
894
|
+
if (data.excludes) {
|
|
895
|
+
for (const part of columnExcludesToCode(data.excludes)) {
|
|
896
|
+
orchidCore.addCode(code, part);
|
|
897
|
+
}
|
|
898
|
+
}
|
|
782
899
|
if (data.comment) orchidCore.addCode(code, `.comment(${orchidCore.singleQuote(data.comment)})`);
|
|
783
900
|
if (data.check) {
|
|
784
901
|
orchidCore.addCode(code, columnCheckToCode(ctx, data.check, name));
|
|
@@ -12030,6 +12147,19 @@ const tableDataMethods = {
|
|
|
12030
12147
|
input.index.options.tsVector = true;
|
|
12031
12148
|
return input;
|
|
12032
12149
|
},
|
|
12150
|
+
exclude(columns, ...[first, second]) {
|
|
12151
|
+
if (typeof first === "string") {
|
|
12152
|
+
const options = second ?? {};
|
|
12153
|
+
return {
|
|
12154
|
+
exclude: { columns, options, name: first }
|
|
12155
|
+
};
|
|
12156
|
+
} else {
|
|
12157
|
+
const options = first ?? {};
|
|
12158
|
+
return {
|
|
12159
|
+
exclude: { columns, options }
|
|
12160
|
+
};
|
|
12161
|
+
}
|
|
12162
|
+
},
|
|
12033
12163
|
foreignKey(columns, fnOrTable, foreignColumns, options) {
|
|
12034
12164
|
return {
|
|
12035
12165
|
constraint: {
|
|
@@ -12061,15 +12191,13 @@ const parseTableDataInput = (tableData, item) => {
|
|
|
12061
12191
|
if (item.primaryKey) {
|
|
12062
12192
|
tableData.primaryKey = item.primaryKey;
|
|
12063
12193
|
} else if (item.index) {
|
|
12064
|
-
|
|
12065
|
-
|
|
12066
|
-
|
|
12067
|
-
|
|
12068
|
-
|
|
12069
|
-
|
|
12070
|
-
|
|
12071
|
-
}
|
|
12072
|
-
(tableData.indexes ?? (tableData.indexes = [])).push(item.index);
|
|
12194
|
+
(tableData.indexes ?? (tableData.indexes = [])).push(
|
|
12195
|
+
parseIndexOrExclude(item.index)
|
|
12196
|
+
);
|
|
12197
|
+
} else if (item.exclude) {
|
|
12198
|
+
(tableData.excludes ?? (tableData.excludes = [])).push(
|
|
12199
|
+
parseIndexOrExclude(item.exclude)
|
|
12200
|
+
);
|
|
12073
12201
|
} else if (item.constraint) {
|
|
12074
12202
|
(tableData.constraints ?? (tableData.constraints = [])).push(item.constraint);
|
|
12075
12203
|
if (item.constraint.references?.options?.dropMode) {
|
|
@@ -12077,6 +12205,16 @@ const parseTableDataInput = (tableData, item) => {
|
|
|
12077
12205
|
}
|
|
12078
12206
|
}
|
|
12079
12207
|
};
|
|
12208
|
+
const parseIndexOrExclude = (item) => {
|
|
12209
|
+
for (let i = item.columns.length - 1; i >= 0; i--) {
|
|
12210
|
+
if (typeof item.columns[i] === "string") {
|
|
12211
|
+
item.columns[i] = {
|
|
12212
|
+
column: item.columns[i]
|
|
12213
|
+
};
|
|
12214
|
+
}
|
|
12215
|
+
}
|
|
12216
|
+
return item;
|
|
12217
|
+
};
|
|
12080
12218
|
|
|
12081
12219
|
const anyShape = {};
|
|
12082
12220
|
class Db extends QueryMethods {
|
|
@@ -12718,6 +12856,7 @@ exports.cloneQuery = cloneQuery;
|
|
|
12718
12856
|
exports.cloneQueryBaseUnscoped = cloneQueryBaseUnscoped;
|
|
12719
12857
|
exports.columnCheckToCode = columnCheckToCode;
|
|
12720
12858
|
exports.columnCode = columnCode;
|
|
12859
|
+
exports.columnExcludesToCode = columnExcludesToCode;
|
|
12721
12860
|
exports.columnForeignKeysToCode = columnForeignKeysToCode;
|
|
12722
12861
|
exports.columnIndexesToCode = columnIndexesToCode;
|
|
12723
12862
|
exports.columnsShapeToCode = columnsShapeToCode;
|
|
@@ -12731,6 +12870,8 @@ exports.defaultSchemaConfig = defaultSchemaConfig;
|
|
|
12731
12870
|
exports.escapeForLog = escapeForLog;
|
|
12732
12871
|
exports.escapeForMigration = escapeForMigration;
|
|
12733
12872
|
exports.escapeString = escapeString;
|
|
12873
|
+
exports.excludeInnerToCode = excludeInnerToCode;
|
|
12874
|
+
exports.excludeToCode = excludeToCode;
|
|
12734
12875
|
exports.extendQuery = extendQuery;
|
|
12735
12876
|
exports.filterResult = filterResult;
|
|
12736
12877
|
exports.foreignKeyArgumentToCode = foreignKeyArgumentToCode;
|