pqb 0.66.5 → 0.66.7

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 CHANGED
@@ -125,6 +125,7 @@ declare const colors: {
125
125
  greenBold: (s: string) => string;
126
126
  pale: (s: string) => string;
127
127
  };
128
+ declare const quoteIdentifier: (role: string) => string;
128
129
  interface SubQueryForSql extends ToSQLQuery {
129
130
  __forSql: true;
130
131
  }
@@ -4394,12 +4395,48 @@ declare class SoftDeleteMethods {
4394
4395
  interface QueryInternalColumnNameToKey {
4395
4396
  columnNameToKeyMap?: Map<string, string>;
4396
4397
  }
4397
- interface TableRlsConfig {
4398
- enable?: boolean;
4399
- force?: boolean;
4398
+ declare namespace RlsPolicy {
4399
+ export type PolicyMode = 'PERMISSIVE' | 'RESTRICTIVE';
4400
+ export type PolicyCommand = 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE';
4401
+ interface Base {
4402
+ name: string;
4403
+ to: string | string[];
4404
+ }
4405
+ export interface ForSelectOrDelete extends Base {
4406
+ for: 'SELECT' | 'DELETE';
4407
+ using: RawSqlBase;
4408
+ withCheck?: never;
4409
+ }
4410
+ export interface ForInsert extends Base {
4411
+ for: 'INSERT';
4412
+ using?: never;
4413
+ withCheck: RawSqlBase;
4414
+ }
4415
+ export interface ForAllOrUpdate extends Base {
4416
+ for?: 'ALL' | 'UPDATE';
4417
+ using: RawSqlBase;
4418
+ withCheck: RawSqlBase;
4419
+ }
4420
+ export type Policy = ForSelectOrDelete | ForInsert | ForAllOrUpdate;
4421
+ export {};
4400
4422
  }
4401
- interface DbRlsOptions {
4402
- tableRlsDefaults?: TableRlsConfig;
4423
+ declare namespace Rls {
4424
+ interface TableConfig {
4425
+ enable?: boolean;
4426
+ force?: boolean;
4427
+ permit: [RlsPolicy.Policy, ...RlsPolicy.Policy[]];
4428
+ restrict?: RlsPolicy.Policy[];
4429
+ }
4430
+ interface TableDefaults {
4431
+ /**
4432
+ * Default RLS table flags for declarations that omit them.
4433
+ */
4434
+ enable?: boolean;
4435
+ force?: boolean;
4436
+ }
4437
+ interface Options {
4438
+ tableRlsDefaults?: TableDefaults;
4439
+ }
4403
4440
  }
4404
4441
  declare namespace DefaultPrivileges {
4405
4442
  export type ObjectType = (typeof DEFAULT_PRIVILEGE.OBJECT_TYPES)[number];
@@ -4477,6 +4514,123 @@ interface DbRole {
4477
4514
  config?: RecordOptionalString;
4478
4515
  defaultPrivileges?: DefaultPrivileges.SchemaConfig[];
4479
4516
  }
4517
+ declare namespace Grant {
4518
+ type Role = string | [string, ...string[]];
4519
+ type TablePrivilege = 'ALL' | 'SELECT' | 'INSERT' | 'UPDATE' | 'DELETE' | 'TRUNCATE' | 'REFERENCES' | 'TRIGGER' | 'MAINTAIN';
4520
+ type SequencePrivilege = 'ALL' | 'USAGE' | 'SELECT' | 'UPDATE';
4521
+ type RoutinePrivilege = 'ALL' | 'EXECUTE';
4522
+ type TypePrivilege = 'ALL' | 'USAGE';
4523
+ type DomainPrivilege = 'ALL' | 'USAGE';
4524
+ type SchemaPrivilege = 'ALL' | 'USAGE' | 'CREATE';
4525
+ type DatabasePrivilege = 'ALL' | 'CREATE' | 'CONNECT' | 'TEMPORARY' | 'TEMP';
4526
+ interface SchemaGrant {
4527
+ to: Role;
4528
+ grantedBy?: string;
4529
+ schemas: string[];
4530
+ privileges?: SchemaPrivilege[];
4531
+ grantablePrivileges?: SchemaPrivilege[];
4532
+ }
4533
+ interface TableGrant {
4534
+ to: Role;
4535
+ grantedBy?: string;
4536
+ tables: string[];
4537
+ privileges?: TablePrivilege[];
4538
+ grantablePrivileges?: TablePrivilege[];
4539
+ }
4540
+ interface TableClassGrant {
4541
+ to: Role;
4542
+ grantedBy?: string;
4543
+ privileges?: TablePrivilege[];
4544
+ grantablePrivileges?: TablePrivilege[];
4545
+ }
4546
+ interface AllTablesInGrant {
4547
+ to: Role;
4548
+ grantedBy?: string;
4549
+ allTablesIn: string[];
4550
+ privileges?: TablePrivilege[];
4551
+ grantablePrivileges?: TablePrivilege[];
4552
+ }
4553
+ interface SequenceGrant {
4554
+ to: Role;
4555
+ grantedBy?: string;
4556
+ sequences: string[];
4557
+ privileges?: SequencePrivilege[];
4558
+ grantablePrivileges?: SequencePrivilege[];
4559
+ }
4560
+ interface AllSequencesInGrant {
4561
+ to: Role;
4562
+ grantedBy?: string;
4563
+ allSequencesIn: string[];
4564
+ privileges?: SequencePrivilege[];
4565
+ grantablePrivileges?: SequencePrivilege[];
4566
+ }
4567
+ interface RoutineGrant {
4568
+ to: Role;
4569
+ grantedBy?: string;
4570
+ routines: string[];
4571
+ privileges?: RoutinePrivilege[];
4572
+ grantablePrivileges?: RoutinePrivilege[];
4573
+ }
4574
+ interface AllRoutinesInGrant {
4575
+ to: Role;
4576
+ grantedBy?: string;
4577
+ allRoutinesIn: string[];
4578
+ privileges?: RoutinePrivilege[];
4579
+ grantablePrivileges?: RoutinePrivilege[];
4580
+ }
4581
+ interface TypeGrant {
4582
+ to: Role;
4583
+ grantedBy?: string;
4584
+ types: string[];
4585
+ privileges?: TypePrivilege[];
4586
+ grantablePrivileges?: TypePrivilege[];
4587
+ }
4588
+ interface DomainGrant {
4589
+ to: Role;
4590
+ grantedBy?: string;
4591
+ domains: string[];
4592
+ privileges?: DomainPrivilege[];
4593
+ grantablePrivileges?: DomainPrivilege[];
4594
+ }
4595
+ interface DatabaseGrant {
4596
+ to: Role;
4597
+ grantedBy?: string;
4598
+ databases: string[];
4599
+ privileges?: DatabasePrivilege[];
4600
+ grantablePrivileges?: DatabasePrivilege[];
4601
+ }
4602
+ type Privilege = SchemaGrant | TableGrant | AllTablesInGrant | SequenceGrant | AllSequencesInGrant | RoutineGrant | AllRoutinesInGrant | TypeGrant | DomainGrant | DatabaseGrant;
4603
+ interface InternalPrivilege {
4604
+ to: string[];
4605
+ grantedBy?: string;
4606
+ schemas?: string[];
4607
+ tables?: string[];
4608
+ allTablesIn?: string[];
4609
+ sequences?: string[];
4610
+ allSequencesIn?: string[];
4611
+ routines?: string[];
4612
+ allRoutinesIn?: string[];
4613
+ types?: string[];
4614
+ domains?: string[];
4615
+ databases?: string[];
4616
+ privileges?: string[];
4617
+ grantablePrivileges?: string[];
4618
+ }
4619
+ type IgnoreSelector = string | RegExp | (string | RegExp)[];
4620
+ interface Ignore {
4621
+ roles?: IgnoreSelector;
4622
+ schemas?: IgnoreSelector;
4623
+ tables?: IgnoreSelector;
4624
+ allTablesIn?: IgnoreSelector;
4625
+ sequences?: IgnoreSelector;
4626
+ allSequencesIn?: IgnoreSelector;
4627
+ routines?: IgnoreSelector;
4628
+ allRoutinesIn?: IgnoreSelector;
4629
+ types?: IgnoreSelector;
4630
+ domains?: IgnoreSelector;
4631
+ databases?: IgnoreSelector;
4632
+ }
4633
+ }
4480
4634
  interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColumnNames = any, UniqueColumnTuples = any, UniqueConstraints = any> extends QueryInternalColumnNameToKey {
4481
4635
  runtimeDefaultColumns?: string[];
4482
4636
  asyncStorage: AsyncLocalStorage<AsyncState>;
@@ -4494,9 +4648,12 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
4494
4648
  domains?: DbDomainArgRecord;
4495
4649
  generatorIgnore?: GeneratorIgnore;
4496
4650
  roles?: DbRole[];
4497
- rls?: DbRlsOptions;
4498
- tableRls?: TableRlsConfig;
4651
+ rls?: Rls.Options;
4652
+ tableRls?: Rls.TableConfig;
4653
+ tableGrants?: Grant.TableClassGrant[];
4499
4654
  managedRolesSql?: string;
4655
+ defaultGrantedBy?: string;
4656
+ grants?: Grant.InternalPrivilege[];
4500
4657
  tableData: TableData;
4501
4658
  nowSQL?: string;
4502
4659
  callbackArg?: Query;
@@ -4513,7 +4670,7 @@ type NoPrimaryKeyOption = 'error' | 'warning' | 'ignore';
4513
4670
  interface DbSharedOptions extends QueryLogOptions {
4514
4671
  autoPreparedStatements?: boolean;
4515
4672
  noPrimaryKey?: NoPrimaryKeyOption;
4516
- rls?: DbRlsOptions;
4673
+ rls?: Rls.Options;
4517
4674
  extensions?: (string | RecordString)[];
4518
4675
  domains?: {
4519
4676
  [K: string]: DbDomainArg<DefaultColumnTypes<DefaultSchemaConfig>>;
@@ -4530,6 +4687,11 @@ interface DbSharedOptions extends QueryLogOptions {
4530
4687
  nestedCreateBatchMax?: number;
4531
4688
  roles?: DbRole[];
4532
4689
  managedRolesSql?: string;
4690
+ /**
4691
+ * Default grantor role for grant metadata.
4692
+ */
4693
+ defaultGrantedBy?: string;
4694
+ grants?: Grant.Privilege[];
4533
4695
  }
4534
4696
  interface DbOptions<SchemaConfig extends ColumnSchemaConfig, ColumnTypes> extends DbSharedOptions {
4535
4697
  schemaConfig?: SchemaConfig;
@@ -5144,7 +5306,7 @@ interface Operator<Value, Column extends Column.Pick.OutputTypeAndOperators = Co
5144
5306
  } : K extends 'returnType' ? 'valueOrThrow' : K extends 'then' ? QueryThen<Column['outputType']> : T[K] } & Column['operators'];
5145
5307
  _opType: Value;
5146
5308
  }
5147
- interface Base<Value> {
5309
+ interface Base$1<Value> {
5148
5310
  __hasSelect: true;
5149
5311
  equals: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
5150
5312
  not: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
@@ -5156,7 +5318,7 @@ interface OperatorsBooleanSelf extends OperatorsBoolean {
5156
5318
  value: BooleanQueryColumn;
5157
5319
  };
5158
5320
  }
5159
- interface Ord<Value> extends Base<Value> {
5321
+ interface Ord<Value> extends Base$1<Value> {
5160
5322
  lt: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
5161
5323
  lte: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
5162
5324
  gt: Operator<Value | IsQuery | Expression, BooleanQueryColumn>;
@@ -5168,7 +5330,7 @@ interface OperatorsBoolean extends Ord<boolean> {
5168
5330
  and: Operator<OperatorsBooleanSelf, BooleanQueryColumn>;
5169
5331
  or: Operator<OperatorsBooleanSelf, BooleanQueryColumn>;
5170
5332
  }
5171
- interface OperatorsText extends Base<string> {
5333
+ interface OperatorsText extends Base$1<string> {
5172
5334
  contains: Operator<string | IsQuery | Expression, BooleanQueryColumn>;
5173
5335
  containsSensitive: Operator<string | IsQuery | Expression, BooleanQueryColumn>;
5174
5336
  startsWith: Operator<string | IsQuery | Expression, BooleanQueryColumn>;
@@ -5350,7 +5512,7 @@ interface OperatorsJson extends Ord<unknown> {
5350
5512
  _opType: never;
5351
5513
  };
5352
5514
  }
5353
- type OperatorsAny = Base<any>;
5515
+ type OperatorsAny = Base$1<any>;
5354
5516
  type OperatorsDate = Ord<Date | string>;
5355
5517
  type OperatorsTime = Ord<string>;
5356
5518
  interface OperatorsArray<T> extends Ord<T[]> {
@@ -9541,8 +9703,8 @@ interface QueryHelperQuery<T extends PickQuerySelectableShapeAs> extends MergeQu
9541
9703
  interface IsQueryHelper {
9542
9704
  isQueryHelper: true;
9543
9705
  table: string | undefined;
9544
- args: unknown[];
9545
- result: unknown;
9706
+ __args: unknown[];
9707
+ __result: unknown;
9546
9708
  }
9547
9709
  interface IsQueryHelperForTable<Table extends string | undefined> extends IsQueryHelper {
9548
9710
  table: Table;
@@ -9551,10 +9713,10 @@ interface QueryHelper<T extends PickQueryTableMetaShapeTableAs, Args extends any
9551
9713
  <Q extends QueryHelperQuery<T>>(q: Q, ...args: Args): Result extends MergeQueryArg ? MergeQuery<Q, Result> : Result;
9552
9714
  __as: T['__as'];
9553
9715
  table: T['table'];
9554
- args: Args;
9555
- result: Result;
9716
+ __args: Args;
9717
+ __result: Result;
9556
9718
  }
9557
- type QueryHelperResult<T extends IsQueryHelper> = T['result'];
9719
+ type QueryHelperResult<T extends IsQueryHelper> = T['__result'];
9558
9720
  interface NarrowTypeSelf extends PickQueryResultReturnType {
9559
9721
  returnType: undefined | 'all' | 'one' | 'oneOrThrow' | 'value' | 'valueOrThrow' | 'pluck';
9560
9722
  }
@@ -9958,7 +10120,7 @@ declare class QueryMethods<ColumnTypes> {
9958
10120
  * @param fn - function to useHelper the query with. The result type will be merged with the main query as if the `merge` method was used.
9959
10121
  * @param args
9960
10122
  */
9961
- useHelper<T extends MergeQueryArg, Fn extends IsQueryHelperForTable<T['table']>>(this: T, fn: Fn, ...args: Fn['args']): Fn['result'] extends MergeQueryArg ? MergeQuery<T, Fn['result']> : Fn['result'];
10123
+ useHelper<T extends MergeQueryArg, Fn extends IsQueryHelperForTable<T['table']>>(this: T, fn: Fn, ...args: Fn['__args']): Fn['__result'] extends MergeQueryArg ? MergeQuery<T, Fn['__result']> : Fn['__result'];
9962
10124
  /**
9963
10125
  * `modify` is useful when you'd like to modify the query based on some condition.
9964
10126
  *
@@ -10027,6 +10189,7 @@ interface GeneratorIgnore {
10027
10189
  domains?: string[];
10028
10190
  extensions?: string[];
10029
10191
  tables?: string[];
10192
+ grants?: Grant.Ignore;
10030
10193
  }
10031
10194
  interface DbDomainArg<ColumnTypes> {
10032
10195
  (columnTypes: ColumnTypes): Column;
@@ -10482,4 +10645,4 @@ declare const testTransaction: {
10482
10645
  */
10483
10646
  close(arg: Arg$1): Promise<void>;
10484
10647
  };
10485
- export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbRlsOptions, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TableRlsConfig, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
10648
+ export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AfterCommitStandaloneHook, type AfterHook, ArrayColumn, type ArrayColumnValue, type ArrayData, type AsyncState, type BaseNumberData, BigIntColumn, BigSerialColumn, BitColumn, BitVaryingColumn, BooleanColumn, BoxColumn, ByteaColumn, CidrColumn, CircleColumn, CitextColumn, type Code, type Codes, Column, type ColumnFromDbParams, type ColumnSchemaConfig, type ColumnSchemaGetterColumns, type ColumnSchemaGetterTableClass, type ColumnToCodeCtx, type ColumnTypeSchemaArg, type ColumnsByType, type ColumnsShape, type ComputedColumnsFromOptions, type ComputedOptionsConfig, type ComputedOptionsFactory, type CreateCtx, type CreateData, type CreateManyMethodsNames, type CreateMethodsNames, type CreateSelf, CustomTypeColumn, DateBaseColumn, DateColumn, type DateColumnData, DateTimeBaseClass, DateTimeTzBaseClass, Db, type DbDomainArg, type DbExtension, type DbOptions, type DbResult, type DbSharedOptions, type DbSqlMethod, type DbStructureDomainsMap, type DbTableOptionScopes, type DbTableOptions, DecimalColumn, type DecimalColumnData, type DefaultColumnTypes, type DefaultPrivileges, type DefaultSchemaConfig, type DeleteMethodsNames, DomainColumn, DoublePrecisionColumn, type DriverAdapter, DynamicRawSQL, type EmptyObject, type EmptyTuple, EnumColumn, Expression, type FromArg, type FromResult, type GeneratorIgnore, Grant, type HookSelectValue, InetColumn, IntegerBaseColumn, IntegerColumn, IntervalColumn, type IsQuery, type IsolationLevel, JSONColumn, JSONTextColumn, type JoinQueryMethod, type JoinedShapes, LimitedTextBaseColumn, LineColumn, LsegColumn, MacAddr8Column, MacAddrColumn, type MapTableScopesOption, type MaybeArray, type MaybePromise, type MergeQuery, MoneyColumn, type NoPrimaryKeyOption, type NonUniqDataItem, NotFoundError, NumberAsStringBaseColumn, NumberBaseColumn, type NumberColumnData, Operators, type OperatorsArray, type OperatorsJson, type OperatorsOrdinalText, OrchidOrmInternalError, type Ord, PathColumn, type PickQueryInputType, type PickQueryInternal, type PickQueryQ, type PickQueryRelations, type PickQuerySelectableRelations, type PickQueryShape, PointColumn, PolygonColumn, PostgisGeographyPointColumn, type Query, type QueryAfterHook, type QueryArraysResult, type QueryBeforeActionHook, type QueryBeforeHook, type QueryData, QueryError, type QueryHasWhere, type QueryHelperResult, QueryHookUtils, QueryHooks, type QueryInternal, type QueryLogObject, type QueryLogOptions, type QueryLogger, type QueryManyTake, type QueryManyTakeOptional, type QueryOrExpression, type QueryResult, type QueryResultRow, type QueryReturnType, type QuerySchema, type QueryScopes, RawSql, type RawSqlBase, RealColumn, type RecordKeyTrue, type RecordOptionalString, type RecordString, type RecordStringOrNumber, type RecordUnknown, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SearchWeight, type SelectableFromShape, SerialColumn, type SerialColumnData, type ShallowSimplify, type ShapeColumnPrimaryKeys, type ShapeUniqueColumns, type SingleSql, type SingleSqlItem, SmallIntColumn, SmallSerialColumn, type Sql, type SqlFn, type SqlSessionState, type StorageOptions, StringColumn, type StringData, type TableData, type TableDataFn, type TableDataInput, type TableDataItem, type TableDataItemsUniqueColumnTuples, type TableDataItemsUniqueColumns, type TableDataItemsUniqueConstraints, type TableDataMethods, type TemplateLiteralArgs, TextBaseColumn, TextColumn, TimeColumn, TimestampColumn, TimestampTZColumn, type Timestamps, type TransactionAdapter, TransactionAdapterClass, type TransactionOptions, TsQueryColumn, TsVectorColumn, UUIDColumn, type UniqueConstraints, type UniqueTableDataItem, UnknownColumn, type UpdateData, type UpsertData, type UpsertThis, VarCharColumn, VirtualColumn, type WhereArg, XMLColumn, _appendQuery, _clone, _createDbSqlMethod, _hookSelectColumns, _initQueryBuilder, _orCreate, _prependWith, _queryCreate, _queryCreateMany, _queryCreateManyFrom, _queryDefaults, _queryDelete, _queryFindBy, _queryFindByOptional, _queryHookAfterCreate, _queryHookAfterUpdate, _queryInsert, _queryInsertMany, _queryJoinOn, _queryRows, _querySelect, _queryTake, _queryTakeOptional, _queryUpdate, _queryUpdateOrThrow, _queryUpsert, _queryWhere, _queryWhereExists, _queryWhereIn, addCode, addTopCte, addTopCteSql, applyMixins, assignDbDataToColumn, backtickQuote, cloneQueryBaseUnscoped, codeToString, colors, columnsShapeToCode, constraintInnerToCode, consumeColumnName, copyTableData, createDbWithAdapter, deepCompare, defaultSchemaConfig, emptyArray, emptyObject, escapeForMigration, escapeString, excludeInnerToCode, exhaustive, getCallerFilePath, getClonedQueryData, getColumnBaseType, getColumnInfo, getColumnTypes, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, referencesArgsToCode, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
package/dist/index.js CHANGED
@@ -6506,7 +6506,7 @@ const setMutativeQueriesSelectRelationsSqlState = (d, as, rel) => {
6506
6506
  const handleInsertAndUpdateSelectRelationsSqlState = (ctx, state) => {
6507
6507
  if (state) ctx.topCtx.mutativeQueriesSelectRelationsSqlState = state;
6508
6508
  };
6509
- const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState, returning) => {
6509
+ const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState) => {
6510
6510
  const selectRelations = relationSelectState?.value;
6511
6511
  if (!selectRelations) return;
6512
6512
  const selectPrimaryKeysQuery = prepareSubQueryForSql(query, _clone(query));
@@ -6514,7 +6514,6 @@ const handleDeleteSelectRelationsSqlState = (ctx, query, relationSelectState, re
6514
6514
  _addToHookSelect(selectPrimaryKeysQuery, primaryKeys, true);
6515
6515
  const { as: cteAs } = moveQueryToCte(ctx, selectPrimaryKeysQuery, void 0, true);
6516
6516
  const relKeys = Object.keys(selectRelations);
6517
- ctx.selectedCount = (returning ? ctx.selectedCount : 0) + relKeys.length;
6518
6517
  const hookSelect = selectPrimaryKeysQuery.q.hookSelect;
6519
6518
  const join = {
6520
6519
  type: "JOIN",
@@ -6840,7 +6839,10 @@ const processWhere = (ands, ctx, table, query, data, quotedAs) => {
6840
6839
  q.q.select = [query.q.expr];
6841
6840
  ands.push(`(${moveMutativeQueryToCte(ctx, q)})`);
6842
6841
  }
6843
- else pushWhereToSql(ands, ctx, query, query.q, query.table && `"${query.table}"`, true);
6842
+ else {
6843
+ const as = getQueryAs(query);
6844
+ pushWhereToSql(ands, ctx, query, query.q, as && `"${as}"`, true);
6845
+ }
6844
6846
  return;
6845
6847
  }
6846
6848
  if (isExpression(data)) {
@@ -7404,7 +7406,7 @@ const pushDeleteSql = (ctx, query, q, quotedAs, isSubSql) => {
7404
7406
  if (q.as && query.table !== q.as) ctx.sql.push(quotedAs);
7405
7407
  const relationSelectState = newMutativeQueriesSelectRelationsSqlState(query);
7406
7408
  let returning = makeReturningSql(ctx, query, q, quotedAs, relationSelectState, "Delete", void 0, isSubSql);
7407
- const selectRelations = handleDeleteSelectRelationsSqlState(ctx, query, relationSelectState, returning);
7409
+ const selectRelations = handleDeleteSelectRelationsSqlState(ctx, query, relationSelectState);
7408
7410
  let join = q.join;
7409
7411
  if (selectRelations) {
7410
7412
  returning = (returning ? returning + ", " : "") + selectRelations.addReturning;
@@ -13051,12 +13053,14 @@ var QueryMethods = class {
13051
13053
  */
13052
13054
  makeHelper(fn) {
13053
13055
  const helperAs = this.q.as || this.table;
13054
- return ((query, ...args) => {
13056
+ const helper = ((query, ...args) => {
13055
13057
  const q = _clone(query);
13056
13058
  const as = _getQueryAs(q);
13057
13059
  if (as) _setQueryAlias(q, as, helperAs);
13058
13060
  return fn(q, ...args);
13059
13061
  });
13062
+ helper.table = this.table;
13063
+ return helper;
13060
13064
  }
13061
13065
  /**
13062
13066
  * `useHelper` allows to use {@link makeHelper} in different queries:
@@ -13647,6 +13651,12 @@ const _initQueryBuilder = (adapter, columnTypes, asyncStorage, commonOptions, op
13647
13651
  qb.internal.generatorIgnore = options.generatorIgnore;
13648
13652
  qb.internal.roles = options.roles;
13649
13653
  qb.internal.managedRolesSql = options.managedRolesSql;
13654
+ qb.internal.defaultGrantedBy = options.defaultGrantedBy;
13655
+ if (options.grants) qb.internal.grants = options.grants.map((grant) => ({
13656
+ ...grant,
13657
+ to: toArray(grant.to)
13658
+ }));
13659
+ qb.internal.rls = options.rls;
13650
13660
  return qb.qb = qb;
13651
13661
  };
13652
13662
  const getSetRoleSql = (parentRole, options) => {
@@ -13738,7 +13748,7 @@ var AdapterClass = class AdapterClass {
13738
13748
  }
13739
13749
  assignError(to, from) {
13740
13750
  const { errorFields } = this.driverAdapter;
13741
- for (const key in errorFields) to[key] = from[key];
13751
+ for (const key in errorFields) to[key] = from[errorFields[key]];
13742
13752
  }
13743
13753
  };
13744
13754
  /**
@@ -14269,6 +14279,12 @@ exports.DoublePrecisionColumn = DoublePrecisionColumn;
14269
14279
  exports.DynamicRawSQL = DynamicRawSQL;
14270
14280
  exports.EnumColumn = EnumColumn;
14271
14281
  exports.Expression = Expression;
14282
+ Object.defineProperty(exports, "Grant", {
14283
+ enumerable: true,
14284
+ get: function() {
14285
+ return Grant;
14286
+ }
14287
+ });
14272
14288
  exports.InetColumn = InetColumn;
14273
14289
  exports.IntegerBaseColumn = IntegerBaseColumn;
14274
14290
  exports.IntegerColumn = IntegerColumn;
@@ -14401,6 +14417,7 @@ exports.primaryKeyInnerToCode = primaryKeyInnerToCode;
14401
14417
  exports.pushQueryOnForOuter = pushQueryOnForOuter;
14402
14418
  exports.pushQueryValueImmutable = pushQueryValueImmutable;
14403
14419
  exports.pushTableDataCode = pushTableDataCode;
14420
+ exports.quoteIdentifier = quoteIdentifier;
14404
14421
  exports.quoteObjectKey = quoteObjectKey;
14405
14422
  exports.quoteTableWithSchema = quoteTableWithSchema;
14406
14423
  exports.raw = raw;