pqb 0.67.5 → 0.67.6
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 +10 -1
- package/dist/index.js +32 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -1
- package/dist/index.mjs.map +1 -1
- package/dist/internal.d.ts +4 -2
- package/dist/internal.js +18 -0
- package/dist/internal.mjs +2 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -4823,6 +4823,7 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4823
4823
|
comment?: string;
|
|
4824
4824
|
readOnly?: boolean;
|
|
4825
4825
|
materialized?: boolean;
|
|
4826
|
+
generatorIgnored?: true;
|
|
4826
4827
|
primaryKeys?: string[];
|
|
4827
4828
|
singlePrimaryKey: SinglePrimaryKey;
|
|
4828
4829
|
uniqueColumns: UniqueColumns;
|
|
@@ -4837,6 +4838,7 @@ interface QueryInternal<SinglePrimaryKey = any, UniqueColumns = any, UniqueColum
|
|
|
4837
4838
|
tableRls?: Rls.TableConfig;
|
|
4838
4839
|
tableGrants?: Grant.TableClassGrant[];
|
|
4839
4840
|
viewData?: {
|
|
4841
|
+
query?: Query;
|
|
4840
4842
|
sql?: string | RawSqlBase;
|
|
4841
4843
|
recursive?: boolean;
|
|
4842
4844
|
checkOption?: 'LOCAL' | 'CASCADED';
|
|
@@ -4928,6 +4930,10 @@ interface DbTableOptions<ColumnTypes, Table extends string | undefined, Shape ex
|
|
|
4928
4930
|
* Mark query objects as backed by a materialized relation.
|
|
4929
4931
|
*/
|
|
4930
4932
|
materialized?: true | undefined;
|
|
4933
|
+
/**
|
|
4934
|
+
* Exclude a table-like definition from migration DDL generation.
|
|
4935
|
+
*/
|
|
4936
|
+
generatorIgnore?: true | undefined;
|
|
4931
4937
|
/**
|
|
4932
4938
|
* Computed SQL or JS columns definitions
|
|
4933
4939
|
*/
|
|
@@ -5318,6 +5324,9 @@ interface BatchSql extends SqlCommonOptions {
|
|
|
5318
5324
|
type Sql = SingleSql | BatchSql;
|
|
5319
5325
|
declare const quoteTableWithSchema: (query: ToSQLQuery) => string;
|
|
5320
5326
|
declare const getSqlText: (sql: Sql) => string;
|
|
5327
|
+
declare const queryToSql: (query: Query) => SingleSql;
|
|
5328
|
+
declare const rawSqlToSql: (sql: string | RawSqlBase) => SingleSql;
|
|
5329
|
+
declare const sqlToRawSql: (sql: SingleSql) => RawSqlBase;
|
|
5321
5330
|
declare class QuerySql<ColumnTypes> {
|
|
5322
5331
|
/**
|
|
5323
5332
|
* @deprecated: use `sql` exported from the `createBaseTable` (see "define a base table" in the docs)
|
|
@@ -10752,4 +10761,4 @@ declare const testTransaction: {
|
|
|
10752
10761
|
*/
|
|
10753
10762
|
close(arg: Arg$1): Promise<void>;
|
|
10754
10763
|
};
|
|
10755
|
-
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, 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 ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type 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 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 RefreshMaterializedViewOptions, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, 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 ToSQLCtx, type ToSqlValues, 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, _appendQueryOnUpsertCreate, _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, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, 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, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
|
10764
|
+
export { type Adapter, AdapterClass, type AdapterConfigBase, type AdapterParams, type AdapterSchemaConfigOptions, 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 ExpressionData, type FromArg, type FromResult, type GeneratorIgnore, type 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 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 RefreshMaterializedViewOptions, type RelationConfigBase, type RelationJoinQuery, type RelationsBase, type Rls, type RlsPolicy, type SchemaConfigFnWithOptions, 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 ToSQLCtx, type ToSqlValues, 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, _appendQueryOnUpsertCreate, _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, getDateAsDateFn, getDateAsNumberFn, getDriverErrorCode, getFreeAlias, getFreeSetAlias, getImportPath, getPrimaryKeys, getQueryAs, getQuerySchema, getShapeFromSelect, getSqlText, getStackTrace, getSupportedDefaultPrivileges, indexInnerToCode, internalSchemaConfig, isExpression, isQueryReturnsAll, isRawSQL, logColors, logParamToLogObject, makeColumnNullable, makeColumnTypes, makeColumnsByType, makeConnectRetryConfig, noop, objectHasValues, omit, parseTableData, parseTableDataInput, pathToLog, pick, pluralize, prepareSubQueryForSql, primaryKeyInnerToCode, pushQueryOnForOuter, pushQueryValueImmutable, pushTableDataCode, queryToSql, quoteIdentifier, quoteObjectKey, quoteTableWithSchema, raw, rawSqlToCode, rawSqlToSql, referencesArgsToCode, refreshMaterializedView, returnArg, setColumnData, setColumnEncode, setColumnParse, setColumnParseNull, setCurrentColumnName, setDataValue, setDefaultLanguage, setFreeAlias, setQueryObjectValueImmutable, singleQuote, sqlToRawSql, tableDataMethods, testTransaction, toArray, toCamelCase, toPascalCase, toSnakeCase, wrapAdapterFnWithConnectRetry };
|
package/dist/index.js
CHANGED
|
@@ -9865,6 +9865,34 @@ const getSqlText = (sql) => {
|
|
|
9865
9865
|
if ("text" in sql) return sql.text;
|
|
9866
9866
|
throw new Error(`Batch SQL is not supported in this query`);
|
|
9867
9867
|
};
|
|
9868
|
+
const queryToSql = (query) => {
|
|
9869
|
+
const sql = query.toSQL();
|
|
9870
|
+
if ("batch" in sql) throw new OrchidOrmInternalError(query, "Batch SQL is not supported in query definitions");
|
|
9871
|
+
return sql;
|
|
9872
|
+
};
|
|
9873
|
+
const rawSqlToSql = (sql) => {
|
|
9874
|
+
if (typeof sql === "string") return { text: sql };
|
|
9875
|
+
const values = [];
|
|
9876
|
+
return {
|
|
9877
|
+
text: sql.toSQL({ values }),
|
|
9878
|
+
values
|
|
9879
|
+
};
|
|
9880
|
+
};
|
|
9881
|
+
const sqlToRawSql = (sql) => {
|
|
9882
|
+
const { values } = sql;
|
|
9883
|
+
if (!values?.length) return raw({ raw: sql.text });
|
|
9884
|
+
const rawValues = {};
|
|
9885
|
+
for (let i = 0; i < values.length; i++) rawValues[`queryValue${i + 1}`] = values[i];
|
|
9886
|
+
return raw({ raw: replaceSqlPlaceholders(sql.text, values.length) }).values(rawValues);
|
|
9887
|
+
};
|
|
9888
|
+
const replaceSqlPlaceholders = (sql, valuesCount) => {
|
|
9889
|
+
const parts = sql.split("'");
|
|
9890
|
+
for (let i = 0; i < parts.length; i += 2) parts[i] = parts[i].replace(/\$(\d+)/g, (match, index) => {
|
|
9891
|
+
const number = Number(index);
|
|
9892
|
+
return number > 0 && number <= valuesCount ? `$queryValue${number}` : match;
|
|
9893
|
+
});
|
|
9894
|
+
return parts.join("'");
|
|
9895
|
+
};
|
|
9868
9896
|
var QuerySql = class {
|
|
9869
9897
|
sql(...args) {
|
|
9870
9898
|
const sql = raw(...args);
|
|
@@ -13917,6 +13945,7 @@ var Db = class extends QueryMethods {
|
|
|
13917
13945
|
comment: options.comment,
|
|
13918
13946
|
readOnly: options.readOnly,
|
|
13919
13947
|
materialized: options.materialized,
|
|
13948
|
+
generatorIgnored: options.generatorIgnore,
|
|
13920
13949
|
nowSQL: options.nowSQL,
|
|
13921
13950
|
viewData,
|
|
13922
13951
|
tableData,
|
|
@@ -14611,11 +14640,13 @@ exports.primaryKeyInnerToCode = primaryKeyInnerToCode;
|
|
|
14611
14640
|
exports.pushQueryOnForOuter = pushQueryOnForOuter;
|
|
14612
14641
|
exports.pushQueryValueImmutable = pushQueryValueImmutable;
|
|
14613
14642
|
exports.pushTableDataCode = pushTableDataCode;
|
|
14643
|
+
exports.queryToSql = queryToSql;
|
|
14614
14644
|
exports.quoteIdentifier = quoteIdentifier;
|
|
14615
14645
|
exports.quoteObjectKey = quoteObjectKey;
|
|
14616
14646
|
exports.quoteTableWithSchema = quoteTableWithSchema;
|
|
14617
14647
|
exports.raw = raw;
|
|
14618
14648
|
exports.rawSqlToCode = rawSqlToCode;
|
|
14649
|
+
exports.rawSqlToSql = rawSqlToSql;
|
|
14619
14650
|
exports.referencesArgsToCode = referencesArgsToCode;
|
|
14620
14651
|
exports.refreshMaterializedView = refreshMaterializedView;
|
|
14621
14652
|
exports.returnArg = returnArg;
|
|
@@ -14629,6 +14660,7 @@ exports.setDefaultLanguage = setDefaultLanguage;
|
|
|
14629
14660
|
exports.setFreeAlias = setFreeAlias;
|
|
14630
14661
|
exports.setQueryObjectValueImmutable = setQueryObjectValueImmutable;
|
|
14631
14662
|
exports.singleQuote = singleQuote;
|
|
14663
|
+
exports.sqlToRawSql = sqlToRawSql;
|
|
14632
14664
|
exports.tableDataMethods = tableDataMethods;
|
|
14633
14665
|
exports.testTransaction = testTransaction;
|
|
14634
14666
|
exports.toArray = toArray;
|