pqb 0.67.1 → 0.67.2
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 +38 -26
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -0
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +9490 -2
- package/dist/internal.js +17 -0
- package/dist/internal.js.map +1 -1
- package/dist/internal.mjs +17 -1
- package/dist/internal.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4455,6 +4455,7 @@ declare class QueryScope {
|
|
|
4455
4455
|
type DeleteMethodsNames = 'delete';
|
|
4456
4456
|
type DeleteArgs<T extends PickQueryHasWhere> = T['__hasWhere'] extends true ? EmptyTuple : [never];
|
|
4457
4457
|
type DeleteResult<T extends PickQueryHasSelectResultReturnType> = T['__hasSelect'] extends true ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsRowCountMany<T> : SetQueryReturnsRowCount<T>;
|
|
4458
|
+
interface DeleteSelf extends PickQueryHasSelectHasWhereResultReturnType, Query.Pick.IsNotReadOnly {}
|
|
4458
4459
|
declare const _queryDelete: <T extends PickQueryHasSelectResultReturnType>(query: T) => DeleteResult<T>;
|
|
4459
4460
|
declare class QueryDelete {
|
|
4460
4461
|
/**
|
|
@@ -4516,10 +4517,10 @@ declare class QueryDelete {
|
|
|
4516
4517
|
* .from('b');
|
|
4517
4518
|
* ```
|
|
4518
4519
|
*/
|
|
4519
|
-
delete<T extends
|
|
4520
|
+
delete<T extends DeleteSelf>(this: T, ..._args: DeleteArgs<T>): DeleteResult<T>;
|
|
4520
4521
|
}
|
|
4521
4522
|
type SoftDeleteOption<Shape extends Column.QueryColumns> = true | keyof Shape;
|
|
4522
|
-
interface QueryWithSoftDelete extends PickQueryResult, PickQueryReturnType, PickQueryHasSelect, PickQueryHasWhere {
|
|
4523
|
+
interface QueryWithSoftDelete extends PickQueryResult, PickQueryReturnType, PickQueryHasSelect, PickQueryHasWhere, Query.Pick.IsNotReadOnly {
|
|
4523
4524
|
__scopes: NonDeletedScope;
|
|
4524
4525
|
}
|
|
4525
4526
|
interface NonDeletedScope {
|
|
@@ -4820,6 +4821,7 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4820
4821
|
snakeCase?: boolean;
|
|
4821
4822
|
noPrimaryKey: boolean;
|
|
4822
4823
|
comment?: string;
|
|
4824
|
+
readOnly?: boolean;
|
|
4823
4825
|
primaryKeys?: string[];
|
|
4824
4826
|
singlePrimaryKey: SinglePrimaryKey;
|
|
4825
4827
|
uniqueColumns: UniqueColumns;
|
|
@@ -4909,6 +4911,10 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
4909
4911
|
* Table comment, for migrations generator
|
|
4910
4912
|
*/
|
|
4911
4913
|
comment?: string;
|
|
4914
|
+
/**
|
|
4915
|
+
* Disallow runtime create, update, and delete operations.
|
|
4916
|
+
*/
|
|
4917
|
+
readOnly?: true | undefined;
|
|
4912
4918
|
/**
|
|
4913
4919
|
* Computed SQL or JS columns definitions
|
|
4914
4920
|
*/
|
|
@@ -4919,10 +4925,10 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
4919
4925
|
nowSQL?: string;
|
|
4920
4926
|
}
|
|
4921
4927
|
type DbTableOptionScopes<Table extends string | undefined, Shape extends Column.QueryColumns, Keys extends string = string> = { [K in Keys]: (q: ScopeArgumentQuery<Table, Shape>) => IsQuery };
|
|
4922
|
-
interface QueryBuilder extends Query {
|
|
4928
|
+
interface QueryBuilder extends Query.NotReadOnlyQuery {
|
|
4923
4929
|
returnType: undefined;
|
|
4924
4930
|
}
|
|
4925
|
-
declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends Column.QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject, DefaultSelect extends keyof Shape = keyof Shape> extends QueryMethods<ColumnTypes> implements Query {
|
|
4931
|
+
declare class Db<Table extends string | undefined = undefined, Shape extends Column.QueryColumnsInit = Column.QueryColumnsInit, PrimaryKeys = never, UniqueColumns = never, UniqueColumnTuples = never, UniqueConstraints = never, ColumnTypes = DefaultColumnTypes<ColumnSchemaConfig>, ShapeWithComputed extends Column.QueryColumnsInit = Shape, Scopes extends RecordUnknown | undefined = EmptyObject, DefaultSelect extends keyof Shape = keyof Shape, ReadOnly extends true | undefined = undefined> extends QueryMethods<ColumnTypes> implements Query {
|
|
4926
4932
|
adapterNotInTransaction: Adapter;
|
|
4927
4933
|
qb: QueryBuilder;
|
|
4928
4934
|
table: Table;
|
|
@@ -4931,6 +4937,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
4931
4937
|
__isQuery: true;
|
|
4932
4938
|
__as: Table & string;
|
|
4933
4939
|
__selectable: SelectableFromShape<ShapeWithComputed, Table>;
|
|
4940
|
+
readOnly: ReadOnly;
|
|
4934
4941
|
__hasSelect: boolean;
|
|
4935
4942
|
__hasWhere: boolean;
|
|
4936
4943
|
__defaults: { [K in { [K in keyof Shape]: unknown extends Shape[K]['data']['default'] ? never : K }[keyof Shape]]: true };
|
|
@@ -5020,9 +5027,7 @@ declare class Db<Table extends string | undefined = undefined, Shape extends Col
|
|
|
5020
5027
|
queryArrays<R extends any[] = any[]>(...args: SQLQueryArgs): Promise<QueryResult<R>>;
|
|
5021
5028
|
}
|
|
5022
5029
|
interface DbTableConstructor<ColumnTypes> {
|
|
5023
|
-
<Table extends string, Shape extends Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>, ColumnsShape.DefaultSelectKeys<Shape
|
|
5024
|
-
ko: Shape;
|
|
5025
|
-
};
|
|
5030
|
+
<Table extends string, Shape extends Column.QueryColumnsInit, Data extends MaybeArray<TableDataItem>, Options extends DbTableOptions<ColumnTypes, Table, Shape>>(table: Table, shape?: ((t: ColumnTypes) => Shape) | Shape, tableData?: TableDataFn<Shape, Data>, options?: Options): Db<Table, Shape, keyof ShapeColumnPrimaryKeys<Shape> extends never ? never : ShapeColumnPrimaryKeys<Shape>, ShapeUniqueColumns<Shape> | TableDataItemsUniqueColumns<Shape, Data>, TableDataItemsUniqueColumnTuples<Shape, Data>, UniqueConstraints<Shape> | TableDataItemsUniqueConstraints<Data>, ColumnTypes, Shape & ComputedColumnsFromOptions<Options['computed']>, MapTableScopesOption<Options>, ColumnsShape.DefaultSelectKeys<Shape>, Options['readOnly'] extends true ? true : undefined>;
|
|
5026
5031
|
}
|
|
5027
5032
|
interface DbSqlMethod<ColumnTypes> {
|
|
5028
5033
|
<T>(...args: StaticSQLArgs): RawSql<Column.Pick.QueryColumnOfType<T>, ColumnTypes>;
|
|
@@ -7486,13 +7491,12 @@ declare class QueryCreateFrom {
|
|
|
7486
7491
|
*/
|
|
7487
7492
|
insertForEachFrom<T extends CreateSelf>(this: T, query: IsQuery): InsertManyFromResult<T>;
|
|
7488
7493
|
}
|
|
7489
|
-
interface CreateSelf extends
|
|
7494
|
+
interface CreateSelf extends PickQueryHasSelect, PickQueryDefaults, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryUniqueProperties, PickQueryInputType, Query.Pick.IsNotReadOnly {}
|
|
7490
7495
|
type CreateData<T extends CreateSelf> = EmptyObject extends T['relations'] ? CreateDataWithDefaults<T, keyof T['__defaults']> : CreateRelationsData<T>;
|
|
7491
7496
|
type CreateDataWithDefaults<T extends CreateSelf, Defaults extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults ? never : K]: K extends Defaults ? never : CreateColumn<T, K> } & { [K in Defaults]?: K extends keyof T['inputType'] ? CreateColumn<T, K> : never };
|
|
7492
7497
|
type CreateDataWithDefaultsForRelations<T extends CreateSelf, Defaults extends keyof T['inputType'], OmitFKeys extends PropertyKey> = { [K in keyof T['inputType'] as K extends Defaults | OmitFKeys ? never : K]: K extends Defaults | OmitFKeys ? never : CreateColumn<T, K> } & { [K in Defaults as K extends OmitFKeys ? never : K]?: CreateColumn<T, K> };
|
|
7493
7498
|
type CreateColumn<T extends CreateSelf, K extends keyof T['inputType']> = T['inputType'][K] | ((q: T) => QueryOrExpression<T['inputType'][K]>);
|
|
7494
|
-
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> &
|
|
7495
|
-
type CreateBelongsToData<T extends CreateSelf> = [T['relations'][keyof T['relations']]['dataForCreate']] extends [never] ? EmptyObject : CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']>;
|
|
7499
|
+
type CreateRelationsData<T extends CreateSelf> = CreateDataWithDefaultsForRelations<T, keyof T['__defaults'], T['relations'][keyof T['relations']]['omitForeignKeyInCreate']> & CreateRelationsDataOmittingFKeys<T, T['relations'][keyof T['relations']]['dataForCreate']> & T['relations'][keyof T['relations']]['optionalDataForCreate'];
|
|
7496
7500
|
type CreateRelationsDataOmittingFKeys<T extends CreateSelf, Union> = (Union extends RelationConfigDataForCreate ? (u: Union['columns'] extends keyof T['__defaults'] ? { [P in Exclude<Union['columns'] & keyof T['inputType'], keyof T['__defaults']>]: CreateColumn<T, P> } & { [P in keyof T['__defaults'] & Union['columns']]?: CreateColumn<T, P> } & Partial<Union['nested']> : { [P in Union['columns'] & keyof T['inputType']]: CreateColumn<T, P> } | Union['nested']) => void : never) extends ((u: infer Obj) => void) ? Obj : never;
|
|
7497
7501
|
type CreateResult<T extends CreateSelf, Data> = T extends {
|
|
7498
7502
|
isCount: true;
|
|
@@ -7877,23 +7881,24 @@ declare class OnConflictQueryBuilder<T extends CreateSelf, Arg extends OnConflic
|
|
|
7877
7881
|
except: keyof T['shape'] | (keyof T['shape'])[];
|
|
7878
7882
|
}): T;
|
|
7879
7883
|
}
|
|
7880
|
-
interface UpdateSelf extends PickQuerySelectable, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryInputType, PickQueryAs, PickQueryHasSelect, PickQueryHasWhere {}
|
|
7881
|
-
type UpdateData<T extends UpdateSelf> =
|
|
7882
|
-
type UpdateColumn<T extends UpdateSelf, Key extends keyof T['inputType']> = T['inputType'][Key] | ((q: { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T ? T[K] : never }) => QueryOrExpression<T['inputType'][Key]>);
|
|
7883
|
-
type UpdateRelationData<T extends UpdateSelf, Rel extends RelationConfigBase> = T['returnType'] extends undefined | 'all' ? Rel['dataForUpdate'] : Rel['dataForUpdateOne'];
|
|
7884
|
+
interface UpdateSelf extends PickQuerySelectable, PickQueryResult, PickQueryRelations, PickQueryWithData, PickQueryReturnType, PickQueryShape, PickQueryInputType, PickQueryAs, PickQueryHasSelect, PickQueryHasWhere, Query.Pick.IsNotReadOnly {}
|
|
7885
|
+
type UpdateData<T extends UpdateSelf> = { [K in keyof T['inputType'] | keyof T['relations']]?: K extends keyof T['inputType'] ? T['inputType'][K] | ((q: { [K in keyof T['relations'] | keyof T]: K extends keyof T['relations'] ? T['relations'][K]['query'] : K extends keyof T ? T[K] : never }) => QueryOrExpression<T['inputType'][K]>) : T['returnType'] extends undefined | 'all' ? T['relations'][K]['dataForUpdate'] : T['relations'][K]['dataForUpdateOne'] };
|
|
7884
7886
|
type UpdateArg<T extends UpdateSelf> = T['__hasWhere'] extends true ? UpdateData<T> : 'Update statement must have where conditions. To update all prefix `update` with `all()`';
|
|
7885
7887
|
type UpdateResult<T extends UpdateSelf> = T['__hasSelect'] extends true ? T : T['returnType'] extends undefined | 'all' ? SetQueryReturnsRowCountMany<T> : SetQueryReturnsRowCount<T>;
|
|
7886
7888
|
type NumericColumns<T extends UpdateSelf> = { [K in keyof T['inputType']]: Exclude<T['shape'][K]['queryType'], string> extends number | bigint | null ? K : never }[keyof T['inputType']];
|
|
7887
7889
|
type ChangeCountArg<T extends UpdateSelf> = NumericColumns<T> | { [K in NumericColumns<T>]?: T['shape'][K]['type'] extends number | null ? number : number | string | bigint };
|
|
7888
|
-
|
|
7889
|
-
|
|
7890
|
-
|
|
7891
|
-
|
|
7890
|
+
interface UpdateManyBySelf extends UpdateSelf {
|
|
7891
|
+
internal: {
|
|
7892
|
+
uniqueColumns: unknown;
|
|
7893
|
+
uniqueColumnNames: unknown;
|
|
7894
|
+
uniqueColumnTuples: unknown;
|
|
7895
|
+
uniqueConstraints: unknown;
|
|
7892
7896
|
};
|
|
7893
|
-
}
|
|
7897
|
+
}
|
|
7898
|
+
type UpdateManyData<T extends UpdateSelf> = ({ [K in keyof T['shape'] as T['shape'][K] extends Column.Modifiers.IsPrimaryKey<string> ? K : never]: T['shape'][K]['queryType'] | Expression } & { [P in keyof T['inputType']]?: T['inputType'][P] | Expression })[];
|
|
7894
7899
|
type UpdateManyByKeys<T extends UpdateManyBySelf> = T['internal']['uniqueColumnNames'] | T['internal']['uniqueColumnTuples'];
|
|
7895
|
-
type UpdateManyByKeyColumns<
|
|
7896
|
-
type UpdateManyByData<T extends UpdateSelf, K
|
|
7900
|
+
type UpdateManyByKeyColumns<K> = K extends string[] ? K[number] : K;
|
|
7901
|
+
type UpdateManyByData<T extends UpdateSelf, K> = ({ [P in K & keyof T['inputType']]: T['inputType'][P] } & { [P in keyof T['inputType']]?: P extends K ? T['inputType'][P] : T['inputType'][P] | Expression })[];
|
|
7897
7902
|
type UpdateManyResult<T extends UpdateSelf> = T['__hasSelect'] extends true ? T['returnType'] extends 'one' | 'oneOrThrow' ? SetQueryReturnsAllResult<T, T['result']> : T['returnType'] extends 'value' | 'valueOrThrow' ? SetQueryReturnsPluckColumnResult<T, T['result']> : SetQueryResult<T, T['result']> : SetQueryReturnsRowCountMany<T>;
|
|
7898
7903
|
declare const _queryUpdate: <T extends UpdateSelf>(updateSelf: T, arg: UpdateArg<T>) => UpdateResult<T>;
|
|
7899
7904
|
declare const _queryUpdateOrThrow: <T extends UpdateSelf>(q: T, arg: UpdateArg<T>) => UpdateResult<T>;
|
|
@@ -8327,7 +8332,7 @@ declare class QueryUpdate {
|
|
|
8327
8332
|
* ]);
|
|
8328
8333
|
* ```
|
|
8329
8334
|
*/
|
|
8330
|
-
updateManyBy<T extends UpdateManyBySelf, Keys extends UpdateManyByKeys<T>, K
|
|
8335
|
+
updateManyBy<T extends UpdateManyBySelf, Keys extends UpdateManyByKeys<T>, K = UpdateManyByKeyColumns<Keys>>(this: T, keys: Keys, data: UpdateManyByData<T, K>): UpdateManyResult<T> & QueryHasWhere;
|
|
8331
8336
|
/**
|
|
8332
8337
|
* Same as {@link updateManyBy}, but skips records with no matching key rather than throwing.
|
|
8333
8338
|
*
|
|
@@ -8338,7 +8343,7 @@ declare class QueryUpdate {
|
|
|
8338
8343
|
* ]);
|
|
8339
8344
|
* ```
|
|
8340
8345
|
*/
|
|
8341
|
-
updateManyByOptional<T extends UpdateManyBySelf, Keys extends UpdateManyByKeys<T>, K
|
|
8346
|
+
updateManyByOptional<T extends UpdateManyBySelf, Keys extends UpdateManyByKeys<T>, K = UpdateManyByKeyColumns<Keys>>(this: T, keys: Keys, data: UpdateManyByData<T, K>): UpdateManyResult<T> & QueryHasWhere;
|
|
8342
8347
|
}
|
|
8343
8348
|
declare abstract class VirtualColumn<Schema extends ColumnSchemaConfig, InputSchema extends Schema['type'] = ReturnType<Schema['never']>> extends Column<Schema, unknown, InputSchema, OperatorsAny> {
|
|
8344
8349
|
dataType: string;
|
|
@@ -9338,7 +9343,7 @@ type UpsertData<T extends UpsertThis, Update extends UpdateData<T>> = {
|
|
|
9338
9343
|
data: Update;
|
|
9339
9344
|
create: UpsertCreate<keyof Update, CreateData<T>> | ((update: Update) => UpsertCreate<keyof Update, CreateData<T>>);
|
|
9340
9345
|
};
|
|
9341
|
-
declare const _queryUpsert: (q: Query, data: UpsertData<UpsertThis, UpdateData<
|
|
9346
|
+
declare const _queryUpsert: (q: Query, data: UpsertData<UpsertThis, UpdateData<UpdateSelf>>) => Query;
|
|
9342
9347
|
declare class QueryUpsert {
|
|
9343
9348
|
/**
|
|
9344
9349
|
* `upsert` tries to update a single record, and then it creates the record if it doesn't yet exist.
|
|
@@ -9725,7 +9730,7 @@ declare class QueryTruncate {
|
|
|
9725
9730
|
*
|
|
9726
9731
|
* @param options - truncate options, may have `cascade: true` and `restartIdentity: true`
|
|
9727
9732
|
*/
|
|
9728
|
-
truncate<T>(this: T, options?: {
|
|
9733
|
+
truncate<T extends Query.Pick.IsNotReadOnly>(this: T, options?: {
|
|
9729
9734
|
restartIdentity?: boolean;
|
|
9730
9735
|
cascade?: boolean;
|
|
9731
9736
|
}): SetQueryReturnsVoid<T>;
|
|
@@ -10281,8 +10286,12 @@ interface Query extends IsQuery, PickQueryTable, PickQueryShape, PickQuerySelect
|
|
|
10281
10286
|
relations: RelationsBase;
|
|
10282
10287
|
relationQueries: IsQueries;
|
|
10283
10288
|
error: new (message: string, length: number, name: QueryErrorName) => QueryError;
|
|
10289
|
+
readOnly: true | undefined;
|
|
10284
10290
|
}
|
|
10285
10291
|
declare namespace Query {
|
|
10292
|
+
interface NotReadOnlyQuery extends Query {
|
|
10293
|
+
readOnly: undefined;
|
|
10294
|
+
}
|
|
10286
10295
|
namespace Order {
|
|
10287
10296
|
type Arg<T extends Order.ArgThis> = Order.Arg<T>;
|
|
10288
10297
|
type Args<T extends Order.ArgThis> = Order.Args<T>;
|
|
@@ -10294,6 +10303,9 @@ declare namespace Query {
|
|
|
10294
10303
|
};
|
|
10295
10304
|
returnType: 'value' | 'valueOrThrow';
|
|
10296
10305
|
}
|
|
10306
|
+
interface IsNotReadOnly {
|
|
10307
|
+
readOnly: undefined;
|
|
10308
|
+
}
|
|
10297
10309
|
}
|
|
10298
10310
|
}
|
|
10299
10311
|
type SelectableOfType<T extends PickQuerySelectable, Type> = { [K in keyof T['__selectable']]: T['__selectable'][K]['column']['type'] extends Type | null ? K : never }[keyof T['__selectable']];
|
|
@@ -10364,7 +10376,7 @@ interface RelationConfigBase extends IsQuery {
|
|
|
10364
10376
|
modifyRelatedQuery?(relatedQuery: IsQuery): (query: IsQuery) => void;
|
|
10365
10377
|
maybeSingle: PickQuerySelectableReturnType;
|
|
10366
10378
|
omitForeignKeyInCreate: PropertyKey;
|
|
10367
|
-
dataForCreate
|
|
10379
|
+
dataForCreate: RelationConfigDataForCreate | undefined;
|
|
10368
10380
|
optionalDataForCreate: unknown;
|
|
10369
10381
|
dataForUpdate: unknown;
|
|
10370
10382
|
dataForUpdateOne: unknown;
|
package/dist/index.js
CHANGED
|
@@ -3501,6 +3501,11 @@ var NestedSqlSessionError = class extends OrchidOrmInternalError {
|
|
|
3501
3501
|
super(query, "Cannot nest SQL session scopes. Outer scope already has role or setConfig defined.");
|
|
3502
3502
|
}
|
|
3503
3503
|
};
|
|
3504
|
+
var CannotMutateReadOnlyTableError = class extends OrchidOrmInternalError {
|
|
3505
|
+
constructor(query) {
|
|
3506
|
+
super(query, "Cannot mutate a readonly table.");
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3504
3509
|
const escape = (value, migration, nested) => {
|
|
3505
3510
|
const type = typeof value;
|
|
3506
3511
|
if (type === "number" || type === "bigint") return String(value);
|
|
@@ -5183,6 +5188,9 @@ const throwIfNoWhere = (q, method) => {
|
|
|
5183
5188
|
const throwIfJoinLateral = (q, method) => {
|
|
5184
5189
|
if (q.q.join?.some((x) => Array.isArray(x) || "s" in x.args && x.args.s)) throw new OrchidOrmInternalError(q, `Cannot join a complex query in ${method}`);
|
|
5185
5190
|
};
|
|
5191
|
+
const throwIfReadOnly = (query) => {
|
|
5192
|
+
if (query.internal.readOnly) throw new CannotMutateReadOnlyTableError(query);
|
|
5193
|
+
};
|
|
5186
5194
|
const throwOnReadOnlyUpdate = (query, column, key) => {
|
|
5187
5195
|
if (column.data.appReadOnly || column.data.readOnly) throw new OrchidOrmInternalError(query, "Trying to update a readonly column", { column: key });
|
|
5188
5196
|
};
|
|
@@ -8480,6 +8488,7 @@ var AggregateMethods = class {
|
|
|
8480
8488
|
* @param data - optionally passed custom data when creating a single record.
|
|
8481
8489
|
*/
|
|
8482
8490
|
const insertFrom = (query, from, many, queryMany, data) => {
|
|
8491
|
+
throwIfReadOnly(query);
|
|
8483
8492
|
const ctx = createCtx();
|
|
8484
8493
|
const obj = data && (Array.isArray(data) ? handleManyData(query, data, ctx) : handleOneData(query, data, ctx));
|
|
8485
8494
|
return insert(query, {
|
|
@@ -8935,17 +8944,21 @@ const insert = (self, { columns, insertFrom, values }, many, queryMany) => {
|
|
|
8935
8944
|
return self;
|
|
8936
8945
|
};
|
|
8937
8946
|
const _queryCreate = (q, data) => {
|
|
8947
|
+
throwIfReadOnly(q);
|
|
8938
8948
|
createSelect(q);
|
|
8939
8949
|
return _queryInsert(q, data);
|
|
8940
8950
|
};
|
|
8941
8951
|
const _queryInsert = (query, data) => {
|
|
8952
|
+
throwIfReadOnly(query);
|
|
8942
8953
|
return insert(query, handleOneData(query, data, createCtx()));
|
|
8943
8954
|
};
|
|
8944
8955
|
const _queryCreateMany = (q, data) => {
|
|
8956
|
+
throwIfReadOnly(q);
|
|
8945
8957
|
createSelect(q);
|
|
8946
8958
|
return _queryInsertMany(q, data);
|
|
8947
8959
|
};
|
|
8948
8960
|
const _queryInsertMany = (q, data) => {
|
|
8961
|
+
throwIfReadOnly(q);
|
|
8949
8962
|
let result = insert(q, handleManyData(q, data, createCtx()), true);
|
|
8950
8963
|
if (!data.length) result = result.none();
|
|
8951
8964
|
return result;
|
|
@@ -11294,6 +11307,7 @@ var QueryGet = class {
|
|
|
11294
11307
|
}
|
|
11295
11308
|
};
|
|
11296
11309
|
const _queryDelete = (query) => {
|
|
11310
|
+
throwIfReadOnly(query);
|
|
11297
11311
|
const q = query.q;
|
|
11298
11312
|
if (!q.select) {
|
|
11299
11313
|
if (q.returnType === "oneOrThrow" || q.returnType === "valueOrThrow") q.throwOnNotFound = true;
|
|
@@ -11477,6 +11491,7 @@ var RefExpression = class extends Expression {
|
|
|
11477
11491
|
};
|
|
11478
11492
|
const _queryUpdateMany = (self, primaryKeys, data, strict) => {
|
|
11479
11493
|
const query = self;
|
|
11494
|
+
throwIfReadOnly(query);
|
|
11480
11495
|
const { q } = query;
|
|
11481
11496
|
const { shape } = q;
|
|
11482
11497
|
q.type = "update";
|
|
@@ -11496,6 +11511,7 @@ const _queryUpdateMany = (self, primaryKeys, data, strict) => {
|
|
|
11496
11511
|
return query;
|
|
11497
11512
|
};
|
|
11498
11513
|
const _queryChangeCounter = (self, op, data) => {
|
|
11514
|
+
throwIfReadOnly(self);
|
|
11499
11515
|
const q = self.q;
|
|
11500
11516
|
q.type = "update";
|
|
11501
11517
|
if (!q.select) {
|
|
@@ -11528,6 +11544,7 @@ const _queryChangeCounter = (self, op, data) => {
|
|
|
11528
11544
|
};
|
|
11529
11545
|
const _queryUpdate = (updateSelf, arg) => {
|
|
11530
11546
|
const query = updateSelf;
|
|
11547
|
+
throwIfReadOnly(query);
|
|
11531
11548
|
const { q } = query;
|
|
11532
11549
|
q.type = "update";
|
|
11533
11550
|
const set = { ...arg };
|
|
@@ -11855,6 +11872,7 @@ var QueryUpdate = class {
|
|
|
11855
11872
|
*/
|
|
11856
11873
|
updateFrom(arg, ...args) {
|
|
11857
11874
|
const q = _clone(this);
|
|
11875
|
+
throwIfReadOnly(q);
|
|
11858
11876
|
const joinArgs = _joinReturningArgs(q, true, arg, args, true);
|
|
11859
11877
|
if (!joinArgs) return _queryNone(q);
|
|
11860
11878
|
joinArgs.u = true;
|
|
@@ -13123,6 +13141,7 @@ var QueryTruncate = class {
|
|
|
13123
13141
|
* @param options - truncate options, may have `cascade: true` and `restartIdentity: true`
|
|
13124
13142
|
*/
|
|
13125
13143
|
truncate(options) {
|
|
13144
|
+
throwIfReadOnly(this);
|
|
13126
13145
|
const query = Object.create(_clone(this));
|
|
13127
13146
|
query.toSQL = () => makeTruncateSql(query, options);
|
|
13128
13147
|
return _queryExec(query);
|
|
@@ -13786,6 +13805,7 @@ var Db = class extends QueryMethods {
|
|
|
13786
13805
|
snakeCase: options.snakeCase,
|
|
13787
13806
|
noPrimaryKey: options.noPrimaryKey === "ignore",
|
|
13788
13807
|
comment: options.comment,
|
|
13808
|
+
readOnly: options.readOnly,
|
|
13789
13809
|
nowSQL: options.nowSQL,
|
|
13790
13810
|
tableData,
|
|
13791
13811
|
selectAllCount
|