UNPKG

@openguardrails/moltguard

Version:

AI agent security plugin for OpenClaw: prompt injection detection, PII sanitization, and monitoring dashboard

1,183 lines (1,129 loc) 152 kB
export const id = 411; export const ids = [411]; export const modules = { /***/ 8575: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Hs: () => (/* binding */ mapColumnsInAliasedSQLToAlias), /* harmony export */ Ht: () => (/* binding */ ColumnAliasProxyHandler), /* harmony export */ h_: () => (/* binding */ TableAliasProxyHandler), /* harmony export */ oG: () => (/* binding */ aliasedTable), /* harmony export */ ug: () => (/* binding */ aliasedTableColumn), /* harmony export */ yY: () => (/* binding */ mapColumnsInSQLToAlias) /* harmony export */ }); /* unused harmony exports RelationTableAliasProxyHandler, aliasedRelation */ /* harmony import */ var _column_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2345); /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724); /* harmony import */ var _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(183); /* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407); /* harmony import */ var _view_common_js__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(6146); class ColumnAliasProxyHandler { constructor(table) { this.table = table; } static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "ColumnAliasProxyHandler"; get(columnObj, prop) { if (prop === "table") { return this.table; } return columnObj[prop]; } } class TableAliasProxyHandler { constructor(alias, replaceOriginalName) { this.alias = alias; this.replaceOriginalName = replaceOriginalName; } static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TableAliasProxyHandler"; get(target, prop) { if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.IsAlias) { return true; } if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Name) { return this.alias; } if (this.replaceOriginalName && prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName) { return this.alias; } if (prop === _view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n) { return { ...target[_view_common_js__WEBPACK_IMPORTED_MODULE_2__/* .ViewBaseConfig */ .n], name: this.alias, isAlias: true }; } if (prop === _table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns) { const columns = target[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns]; if (!columns) { return columns; } const proxiedColumns = {}; Object.keys(columns).map((key) => { proxiedColumns[key] = new Proxy( columns[key], new ColumnAliasProxyHandler(new Proxy(target, this)) ); }); return proxiedColumns; } const value = target[prop]; if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(value, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) { return new Proxy(value, new ColumnAliasProxyHandler(new Proxy(target, this))); } return value; } } class RelationTableAliasProxyHandler { constructor(alias) { this.alias = alias; } static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = (/* unused pure expression or super */ null && ("RelationTableAliasProxyHandler")); get(target, prop) { if (prop === "sourceTable") { return aliasedTable(target.sourceTable, this.alias); } return target[prop]; } } function aliasedTable(table, tableAlias) { return new Proxy(table, new TableAliasProxyHandler(tableAlias, false)); } function aliasedRelation(relation, tableAlias) { return new Proxy(relation, new RelationTableAliasProxyHandler(tableAlias)); } function aliasedTableColumn(column, tableAlias) { return new Proxy( column, new ColumnAliasProxyHandler(new Proxy(column.table, new TableAliasProxyHandler(tableAlias, false))) ); } function mapColumnsInAliasedSQLToAlias(query, alias) { return new _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased(mapColumnsInSQLToAlias(query.sql, alias), query.fieldAlias); } function mapColumnsInSQLToAlias(query, alias) { return _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .sql */ .ll.join(query.queryChunks.map((c) => { if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _column_js__WEBPACK_IMPORTED_MODULE_3__/* .Column */ .V)) { return aliasedTableColumn(c, alias); } if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs)) { return mapColumnsInSQLToAlias(c, alias); } if ((0,_entity_js__WEBPACK_IMPORTED_MODULE_0__.is)(c, _sql_sql_js__WEBPACK_IMPORTED_MODULE_4__/* .SQL */ .Xs.Aliased)) { return mapColumnsInAliasedSQLToAlias(c, alias); } return c; })); } //# sourceMappingURL=alias.js.map /***/ }), /***/ 568: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ Yn: () => (/* binding */ CasingCache) /* harmony export */ }); /* unused harmony exports toCamelCase, toSnakeCase */ /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724); /* harmony import */ var _table_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(8407); function toSnakeCase(input) { const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []; return words.map((word) => word.toLowerCase()).join("_"); } function toCamelCase(input) { const words = input.replace(/['\u2019]/g, "").match(/[\da-z]+|[A-Z]+(?![a-z])|[A-Z][\da-z]+/g) ?? []; return words.reduce((acc, word, i) => { const formattedWord = i === 0 ? word.toLowerCase() : `${word[0].toUpperCase()}${word.slice(1)}`; return acc + formattedWord; }, ""); } function noopCase(input) { return input; } class CasingCache { static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "CasingCache"; /** @internal */ cache = {}; cachedTables = {}; convert; constructor(casing) { this.convert = casing === "snake_case" ? toSnakeCase : casing === "camelCase" ? toCamelCase : noopCase; } getColumnCasing(column) { if (!column.keyAsName) return column.name; const schema = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public"; const tableName = column.table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName]; const key = `${schema}.${tableName}.${column.name}`; if (!this.cache[key]) { this.cacheTable(column.table); } return this.cache[key]; } cacheTable(table) { const schema = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Schema] ?? "public"; const tableName = table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.OriginalName]; const tableKey = `${schema}.${tableName}`; if (!this.cachedTables[tableKey]) { for (const column of Object.values(table[_table_js__WEBPACK_IMPORTED_MODULE_1__/* .Table */ .XI.Symbol.Columns])) { const columnKey = `${tableKey}.${column.name}`; this.cache[columnKey] = this.convert(column.name); } this.cachedTables[tableKey] = true; } } clearCache() { this.cache = {}; this.cachedTables = {}; } } //# sourceMappingURL=casing.js.map /***/ }), /***/ 6920: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { /* harmony export */ __webpack_require__.d(__webpack_exports__, { /* harmony export */ j: () => (/* binding */ TransactionRollbackError), /* harmony export */ n: () => (/* binding */ DrizzleError) /* harmony export */ }); /* harmony import */ var _entity_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(9724); class DrizzleError extends Error { static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "DrizzleError"; constructor({ message, cause }) { super(message); this.name = "DrizzleError"; this.cause = cause; } } class TransactionRollbackError extends DrizzleError { static [_entity_js__WEBPACK_IMPORTED_MODULE_0__/* .entityKind */ .i] = "TransactionRollbackError"; constructor() { super({ message: "Rollback" }); } } //# sourceMappingURL=errors.js.map /***/ }), /***/ 3411: /***/ ((__unused_webpack___webpack_module__, __webpack_exports__, __webpack_require__) => { // EXPORTS __webpack_require__.d(__webpack_exports__, { drizzle: () => (/* reexport */ drizzle) }); // UNUSED EXPORTS: LibSQLDatabase, LibSQLPreparedQuery, LibSQLSession, LibSQLTransaction // EXTERNAL MODULE: external "@libsql/client" var client_ = __webpack_require__(8855); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/utils.js var utils = __webpack_require__(3853); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/entity.js var entity = __webpack_require__(9724); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/logger.js var drizzle_orm_logger = __webpack_require__(6743); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/relations.js + 1 modules var relations = __webpack_require__(4750); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/selection-proxy.js var selection_proxy = __webpack_require__(8296); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/sql.js + 1 modules var sql = __webpack_require__(183); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/alias.js var alias = __webpack_require__(8575); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/casing.js var casing = __webpack_require__(568); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/column.js var column = __webpack_require__(2345); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/errors.js var errors = __webpack_require__(6920); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sql/expressions/conditions.js var conditions = __webpack_require__(420); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sqlite-core/columns/common.js + 2 modules var common = __webpack_require__(3824); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sqlite-core/table.js + 4 modules var sqlite_core_table = __webpack_require__(2084); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/subquery.js var subquery = __webpack_require__(6453); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/table.js var drizzle_orm_table = __webpack_require__(8407); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/view-common.js var view_common = __webpack_require__(6146); ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sqlite-core/view-base.js class SQLiteViewBase extends sql/* View */.Ss { static [entity/* entityKind */.i] = "SQLiteViewBase"; } //# sourceMappingURL=view-base.js.map ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sqlite-core/dialect.js class SQLiteDialect { static [entity/* entityKind */.i] = "SQLiteDialect"; /** @internal */ casing; constructor(config) { this.casing = new casing/* CasingCache */.Yn(config?.casing); } escapeName(name) { return `"${name}"`; } escapeParam(_num) { return "?"; } escapeString(str) { return `'${str.replace(/'/g, "''")}'`; } buildWithCTE(queries) { if (!queries?.length) return void 0; const withSqlChunks = [(0,sql/* sql */.ll)`with `]; for (const [i, w] of queries.entries()) { withSqlChunks.push((0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(w._.alias)} as (${w._.sql})`); if (i < queries.length - 1) { withSqlChunks.push((0,sql/* sql */.ll)`, `); } } withSqlChunks.push((0,sql/* sql */.ll)` `); return sql/* sql */.ll.join(withSqlChunks); } buildDeleteQuery({ table, where, returning, withList, limit, orderBy }) { const withSql = this.buildWithCTE(withList); const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0; const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0; const orderBySql = this.buildOrderBy(orderBy); const limitSql = this.buildLimit(limit); return (0,sql/* sql */.ll)`${withSql}delete from ${table}${whereSql}${returningSql}${orderBySql}${limitSql}`; } buildUpdateSet(table, set) { const tableColumns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns]; const columnNames = Object.keys(tableColumns).filter( (colName) => set[colName] !== void 0 || tableColumns[colName]?.onUpdateFn !== void 0 ); const setSize = columnNames.length; return sql/* sql */.ll.join(columnNames.flatMap((colName, i) => { const col = tableColumns[colName]; const value = set[colName] ?? sql/* sql */.ll.param(col.onUpdateFn(), col); const res = (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(this.casing.getColumnCasing(col))} = ${value}`; if (i < setSize - 1) { return [res, sql/* sql */.ll.raw(", ")]; } return [res]; })); } buildUpdateQuery({ table, set, where, returning, withList, joins, from, limit, orderBy }) { const withSql = this.buildWithCTE(withList); const setSql = this.buildUpdateSet(table, set); const fromSql = from && sql/* sql */.ll.join([sql/* sql */.ll.raw(" from "), this.buildFromTable(from)]); const joinsSql = this.buildJoins(joins); const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0; const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0; const orderBySql = this.buildOrderBy(orderBy); const limitSql = this.buildLimit(limit); return (0,sql/* sql */.ll)`${withSql}update ${table} set ${setSql}${fromSql}${joinsSql}${whereSql}${returningSql}${orderBySql}${limitSql}`; } /** * Builds selection SQL with provided fields/expressions * * Examples: * * `select <selection> from` * * `insert ... returning <selection>` * * If `isSingleTable` is true, then columns won't be prefixed with table name */ buildSelection(fields, { isSingleTable = false } = {}) { const columnsLen = fields.length; const chunks = fields.flatMap(({ field }, i) => { const chunk = []; if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) && field.isSelectionField) { chunk.push(sql/* sql */.ll.identifier(field.fieldAlias)); } else if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased) || (0,entity.is)(field, sql/* SQL */.Xs)) { const query = (0,entity.is)(field, sql/* SQL */.Xs.Aliased) ? field.sql : field; if (isSingleTable) { chunk.push( new sql/* SQL */.Xs( query.queryChunks.map((c) => { if ((0,entity.is)(c, column/* Column */.V)) { return sql/* sql */.ll.identifier(this.casing.getColumnCasing(c)); } return c; }) ) ); } else { chunk.push(query); } if ((0,entity.is)(field, sql/* SQL */.Xs.Aliased)) { chunk.push((0,sql/* sql */.ll)` as ${sql/* sql */.ll.identifier(field.fieldAlias)}`); } } else if ((0,entity.is)(field, column/* Column */.V)) { const tableName = field.table[drizzle_orm_table/* Table */.XI.Symbol.Name]; if (isSingleTable) { chunk.push(sql/* sql */.ll.identifier(this.casing.getColumnCasing(field))); } else { chunk.push((0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(tableName)}.${sql/* sql */.ll.identifier(this.casing.getColumnCasing(field))}`); } } if (i < columnsLen - 1) { chunk.push((0,sql/* sql */.ll)`, `); } return chunk; }); return sql/* sql */.ll.join(chunks); } buildJoins(joins) { if (!joins || joins.length === 0) { return void 0; } const joinsArray = []; if (joins) { for (const [index, joinMeta] of joins.entries()) { if (index === 0) { joinsArray.push((0,sql/* sql */.ll)` `); } const table = joinMeta.table; if ((0,entity.is)(table, sqlite_core_table/* SQLiteTable */.jo)) { const tableName = table[sqlite_core_table/* SQLiteTable */.jo.Symbol.Name]; const tableSchema = table[sqlite_core_table/* SQLiteTable */.jo.Symbol.Schema]; const origTableName = table[sqlite_core_table/* SQLiteTable */.jo.Symbol.OriginalName]; const alias = tableName === origTableName ? void 0 : joinMeta.alias; joinsArray.push( (0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join ${tableSchema ? (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(tableSchema)}.` : void 0}${sql/* sql */.ll.identifier(origTableName)}${alias && (0,sql/* sql */.ll)` ${sql/* sql */.ll.identifier(alias)}`} on ${joinMeta.on}` ); } else { joinsArray.push( (0,sql/* sql */.ll)`${sql/* sql */.ll.raw(joinMeta.joinType)} join ${table} on ${joinMeta.on}` ); } if (index < joins.length - 1) { joinsArray.push((0,sql/* sql */.ll)` `); } } } return sql/* sql */.ll.join(joinsArray); } buildLimit(limit) { return typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0; } buildOrderBy(orderBy) { const orderByList = []; if (orderBy) { for (const [index, orderByValue] of orderBy.entries()) { orderByList.push(orderByValue); if (index < orderBy.length - 1) { orderByList.push((0,sql/* sql */.ll)`, `); } } } return orderByList.length > 0 ? (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderByList)}` : void 0; } buildFromTable(table) { if ((0,entity.is)(table, drizzle_orm_table/* Table */.XI) && table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName] !== table[drizzle_orm_table/* Table */.XI.Symbol.Name]) { return (0,sql/* sql */.ll)`${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.OriginalName])} ${sql/* sql */.ll.identifier(table[drizzle_orm_table/* Table */.XI.Symbol.Name])}`; } return table; } buildSelectQuery({ withList, fields, fieldsFlat, where, having, table, joins, orderBy, groupBy, limit, offset, distinct, setOperators }) { const fieldsList = fieldsFlat ?? (0,utils/* orderSelectedFields */.He)(fields); for (const f of fieldsList) { if ((0,entity.is)(f.field, column/* Column */.V) && (0,drizzle_orm_table/* getTableName */.Io)(f.field.table) !== ((0,entity.is)(table, subquery/* Subquery */.n) ? table._.alias : (0,entity.is)(table, SQLiteViewBase) ? table[view_common/* ViewBaseConfig */.n].name : (0,entity.is)(table, sql/* SQL */.Xs) ? void 0 : (0,drizzle_orm_table/* getTableName */.Io)(table)) && !((table2) => joins?.some( ({ alias }) => alias === (table2[drizzle_orm_table/* Table */.XI.Symbol.IsAlias] ? (0,drizzle_orm_table/* getTableName */.Io)(table2) : table2[drizzle_orm_table/* Table */.XI.Symbol.BaseName]) ))(f.field.table)) { const tableName = (0,drizzle_orm_table/* getTableName */.Io)(f.field.table); throw new Error( `Your "${f.path.join("->")}" field references a column "${tableName}"."${f.field.name}", but the table "${tableName}" is not part of the query! Did you forget to join it?` ); } } const isSingleTable = !joins || joins.length === 0; const withSql = this.buildWithCTE(withList); const distinctSql = distinct ? (0,sql/* sql */.ll)` distinct` : void 0; const selection = this.buildSelection(fieldsList, { isSingleTable }); const tableSql = this.buildFromTable(table); const joinsSql = this.buildJoins(joins); const whereSql = where ? (0,sql/* sql */.ll)` where ${where}` : void 0; const havingSql = having ? (0,sql/* sql */.ll)` having ${having}` : void 0; const groupByList = []; if (groupBy) { for (const [index, groupByValue] of groupBy.entries()) { groupByList.push(groupByValue); if (index < groupBy.length - 1) { groupByList.push((0,sql/* sql */.ll)`, `); } } } const groupBySql = groupByList.length > 0 ? (0,sql/* sql */.ll)` group by ${sql/* sql */.ll.join(groupByList)}` : void 0; const orderBySql = this.buildOrderBy(orderBy); const limitSql = this.buildLimit(limit); const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0; const finalQuery = (0,sql/* sql */.ll)`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}`; if (setOperators.length > 0) { return this.buildSetOperations(finalQuery, setOperators); } return finalQuery; } buildSetOperations(leftSelect, setOperators) { const [setOperator, ...rest] = setOperators; if (!setOperator) { throw new Error("Cannot pass undefined values to any set operator"); } if (rest.length === 0) { return this.buildSetOperationQuery({ leftSelect, setOperator }); } return this.buildSetOperations( this.buildSetOperationQuery({ leftSelect, setOperator }), rest ); } buildSetOperationQuery({ leftSelect, setOperator: { type, isAll, rightSelect, limit, orderBy, offset } }) { const leftChunk = (0,sql/* sql */.ll)`${leftSelect.getSQL()} `; const rightChunk = (0,sql/* sql */.ll)`${rightSelect.getSQL()}`; let orderBySql; if (orderBy && orderBy.length > 0) { const orderByValues = []; for (const singleOrderBy of orderBy) { if ((0,entity.is)(singleOrderBy, common/* SQLiteColumn */.v)) { orderByValues.push(sql/* sql */.ll.identifier(singleOrderBy.name)); } else if ((0,entity.is)(singleOrderBy, sql/* SQL */.Xs)) { for (let i = 0; i < singleOrderBy.queryChunks.length; i++) { const chunk = singleOrderBy.queryChunks[i]; if ((0,entity.is)(chunk, common/* SQLiteColumn */.v)) { singleOrderBy.queryChunks[i] = sql/* sql */.ll.identifier(this.casing.getColumnCasing(chunk)); } } orderByValues.push((0,sql/* sql */.ll)`${singleOrderBy}`); } else { orderByValues.push((0,sql/* sql */.ll)`${singleOrderBy}`); } } orderBySql = (0,sql/* sql */.ll)` order by ${sql/* sql */.ll.join(orderByValues, (0,sql/* sql */.ll)`, `)}`; } const limitSql = typeof limit === "object" || typeof limit === "number" && limit >= 0 ? (0,sql/* sql */.ll)` limit ${limit}` : void 0; const operatorChunk = sql/* sql */.ll.raw(`${type} ${isAll ? "all " : ""}`); const offsetSql = offset ? (0,sql/* sql */.ll)` offset ${offset}` : void 0; return (0,sql/* sql */.ll)`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`; } buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) { const valuesSqlList = []; const columns = table[drizzle_orm_table/* Table */.XI.Symbol.Columns]; const colEntries = Object.entries(columns).filter( ([_, col]) => !col.shouldDisableInsert() ); const insertOrder = colEntries.map(([, column]) => sql/* sql */.ll.identifier(this.casing.getColumnCasing(column))); if (select) { const select2 = valuesOrSelect; if ((0,entity.is)(select2, sql/* SQL */.Xs)) { valuesSqlList.push(select2); } else { valuesSqlList.push(select2.getSQL()); } } else { const values = valuesOrSelect; valuesSqlList.push(sql/* sql */.ll.raw("values ")); for (const [valueIndex, value] of values.entries()) { const valueList = []; for (const [fieldName, col] of colEntries) { const colValue = value[fieldName]; if (colValue === void 0 || (0,entity.is)(colValue, sql/* Param */.Iw) && colValue.value === void 0) { let defaultValue; if (col.default !== null && col.default !== void 0) { defaultValue = (0,entity.is)(col.default, sql/* SQL */.Xs) ? col.default : sql/* sql */.ll.param(col.default, col); } else if (col.defaultFn !== void 0) { const defaultFnResult = col.defaultFn(); defaultValue = (0,entity.is)(defaultFnResult, sql/* SQL */.Xs) ? defaultFnResult : sql/* sql */.ll.param(defaultFnResult, col); } else if (!col.default && col.onUpdateFn !== void 0) { const onUpdateFnResult = col.onUpdateFn(); defaultValue = (0,entity.is)(onUpdateFnResult, sql/* SQL */.Xs) ? onUpdateFnResult : sql/* sql */.ll.param(onUpdateFnResult, col); } else { defaultValue = (0,sql/* sql */.ll)`null`; } valueList.push(defaultValue); } else { valueList.push(colValue); } } valuesSqlList.push(valueList); if (valueIndex < values.length - 1) { valuesSqlList.push((0,sql/* sql */.ll)`, `); } } } const withSql = this.buildWithCTE(withList); const valuesSql = sql/* sql */.ll.join(valuesSqlList); const returningSql = returning ? (0,sql/* sql */.ll)` returning ${this.buildSelection(returning, { isSingleTable: true })}` : void 0; const onConflictSql = onConflict ? (0,sql/* sql */.ll)` on conflict ${onConflict}` : void 0; return (0,sql/* sql */.ll)`${withSql}insert into ${table} ${insertOrder} ${valuesSql}${onConflictSql}${returningSql}`; } sqlToQuery(sql2, invokeSource) { return sql2.toQuery({ casing: this.casing, escapeName: this.escapeName, escapeParam: this.escapeParam, escapeString: this.escapeString, invokeSource }); } buildRelationalQuery({ fullSchema, schema, tableNamesMap, table, tableConfig, queryConfig: config, tableAlias, nestedQueryRelation, joinOn }) { let selection = []; let limit, offset, orderBy = [], where; const joins = []; if (config === true) { const selectionEntries = Object.entries(tableConfig.columns); selection = selectionEntries.map(([key, value]) => ({ dbKey: value.name, tsKey: key, field: (0,alias/* aliasedTableColumn */.ug)(value, tableAlias), relationTableTsKey: void 0, isJson: false, selection: [] })); } else { const aliasedColumns = Object.fromEntries( Object.entries(tableConfig.columns).map(([key, value]) => [key, (0,alias/* aliasedTableColumn */.ug)(value, tableAlias)]) ); if (config.where) { const whereSql = typeof config.where === "function" ? config.where(aliasedColumns, (0,relations/* getOperators */.mm)()) : config.where; where = whereSql && (0,alias/* mapColumnsInSQLToAlias */.yY)(whereSql, tableAlias); } const fieldsSelection = []; let selectedColumns = []; if (config.columns) { let isIncludeMode = false; for (const [field, value] of Object.entries(config.columns)) { if (value === void 0) { continue; } if (field in tableConfig.columns) { if (!isIncludeMode && value === true) { isIncludeMode = true; } selectedColumns.push(field); } } if (selectedColumns.length > 0) { selectedColumns = isIncludeMode ? selectedColumns.filter((c) => config.columns?.[c] === true) : Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key)); } } else { selectedColumns = Object.keys(tableConfig.columns); } for (const field of selectedColumns) { const column = tableConfig.columns[field]; fieldsSelection.push({ tsKey: field, value: column }); } let selectedRelations = []; if (config.with) { selectedRelations = Object.entries(config.with).filter((entry) => !!entry[1]).map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey] })); } let extras; if (config.extras) { extras = typeof config.extras === "function" ? config.extras(aliasedColumns, { sql: sql/* sql */.ll }) : config.extras; for (const [tsKey, value] of Object.entries(extras)) { fieldsSelection.push({ tsKey, value: (0,alias/* mapColumnsInAliasedSQLToAlias */.Hs)(value, tableAlias) }); } } for (const { tsKey, value } of fieldsSelection) { selection.push({ dbKey: (0,entity.is)(value, sql/* SQL */.Xs.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey].name, tsKey, field: (0,entity.is)(value, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(value, tableAlias) : value, relationTableTsKey: void 0, isJson: false, selection: [] }); } let orderByOrig = typeof config.orderBy === "function" ? config.orderBy(aliasedColumns, (0,relations/* getOrderByOperators */.rl)()) : config.orderBy ?? []; if (!Array.isArray(orderByOrig)) { orderByOrig = [orderByOrig]; } orderBy = orderByOrig.map((orderByValue) => { if ((0,entity.is)(orderByValue, column/* Column */.V)) { return (0,alias/* aliasedTableColumn */.ug)(orderByValue, tableAlias); } return (0,alias/* mapColumnsInSQLToAlias */.yY)(orderByValue, tableAlias); }); limit = config.limit; offset = config.offset; for (const { tsKey: selectedRelationTsKey, queryConfig: selectedRelationConfigValue, relation } of selectedRelations) { const normalizedRelation = (0,relations/* normalizeRelation */.W0)(schema, tableNamesMap, relation); const relationTableName = (0,drizzle_orm_table/* getTableUniqueName */.Lf)(relation.referencedTable); const relationTableTsName = tableNamesMap[relationTableName]; const relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`; const joinOn2 = (0,conditions/* and */.Uo)( ...normalizedRelation.fields.map( (field2, i) => (0,conditions.eq)( (0,alias/* aliasedTableColumn */.ug)(normalizedRelation.references[i], relationTableAlias), (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias) ) ) ); const builtRelation = this.buildRelationalQuery({ fullSchema, schema, tableNamesMap, table: fullSchema[relationTableTsName], tableConfig: schema[relationTableTsName], queryConfig: (0,entity.is)(relation, relations/* One */.pD) ? selectedRelationConfigValue === true ? { limit: 1 } : { ...selectedRelationConfigValue, limit: 1 } : selectedRelationConfigValue, tableAlias: relationTableAlias, joinOn: joinOn2, nestedQueryRelation: relation }); const field = (0,sql/* sql */.ll)`(${builtRelation.sql})`.as(selectedRelationTsKey); selection.push({ dbKey: selectedRelationTsKey, tsKey: selectedRelationTsKey, field, relationTableTsKey: relationTableTsName, isJson: true, selection: builtRelation.selection }); } } if (selection.length === 0) { throw new errors/* DrizzleError */.n({ message: `No fields selected for table "${tableConfig.tsName}" ("${tableAlias}"). You need to have at least one item in "columns", "with" or "extras". If you need to select all columns, omit the "columns" key or set it to undefined.` }); } let result; where = (0,conditions/* and */.Uo)(joinOn, where); if (nestedQueryRelation) { let field = (0,sql/* sql */.ll)`json_array(${sql/* sql */.ll.join( selection.map( ({ field: field2 }) => (0,entity.is)(field2, common/* SQLiteColumn */.v) ? sql/* sql */.ll.identifier(this.casing.getColumnCasing(field2)) : (0,entity.is)(field2, sql/* SQL */.Xs.Aliased) ? field2.sql : field2 ), (0,sql/* sql */.ll)`, ` )})`; if ((0,entity.is)(nestedQueryRelation, relations/* Many */.iv)) { field = (0,sql/* sql */.ll)`coalesce(json_group_array(${field}), json_array())`; } const nestedSelection = [{ dbKey: "data", tsKey: "data", field: field.as("data"), isJson: true, relationTableTsKey: tableConfig.tsName, selection }]; const needsSubquery = limit !== void 0 || offset !== void 0 || orderBy.length > 0; if (needsSubquery) { result = this.buildSelectQuery({ table: (0,alias/* aliasedTable */.oG)(table, tableAlias), fields: {}, fieldsFlat: [ { path: [], field: sql/* sql */.ll.raw("*") } ], where, limit, offset, orderBy, setOperators: [] }); where = void 0; limit = void 0; offset = void 0; orderBy = void 0; } else { result = (0,alias/* aliasedTable */.oG)(table, tableAlias); } result = this.buildSelectQuery({ table: (0,entity.is)(result, sqlite_core_table/* SQLiteTable */.jo) ? result : new subquery/* Subquery */.n(result, {}, tableAlias), fields: {}, fieldsFlat: nestedSelection.map(({ field: field2 }) => ({ path: [], field: (0,entity.is)(field2, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field2, tableAlias) : field2 })), joins, where, limit, offset, orderBy, setOperators: [] }); } else { result = this.buildSelectQuery({ table: (0,alias/* aliasedTable */.oG)(table, tableAlias), fields: {}, fieldsFlat: selection.map(({ field }) => ({ path: [], field: (0,entity.is)(field, column/* Column */.V) ? (0,alias/* aliasedTableColumn */.ug)(field, tableAlias) : field })), joins, where, limit, offset, orderBy, setOperators: [] }); } return { tableTsKey: tableConfig.tsName, sql: result, selection }; } } class SQLiteSyncDialect extends SQLiteDialect { static [entity/* entityKind */.i] = "SQLiteSyncDialect"; migrate(migrations, session, config) { const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations"; const migrationTableCreate = (0,sql/* sql */.ll)` CREATE TABLE IF NOT EXISTS ${sql/* sql */.ll.identifier(migrationsTable)} ( id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric ) `; session.run(migrationTableCreate); const dbMigrations = session.values( (0,sql/* sql */.ll)`SELECT id, hash, created_at FROM ${sql/* sql */.ll.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1` ); const lastDbMigration = dbMigrations[0] ?? void 0; session.run((0,sql/* sql */.ll)`BEGIN`); try { for (const migration of migrations) { if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) { for (const stmt of migration.sql) { session.run(sql/* sql */.ll.raw(stmt)); } session.run( (0,sql/* sql */.ll)`INSERT INTO ${sql/* sql */.ll.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})` ); } } session.run((0,sql/* sql */.ll)`COMMIT`); } catch (e) { session.run((0,sql/* sql */.ll)`ROLLBACK`); throw e; } } } class SQLiteAsyncDialect extends SQLiteDialect { static [entity/* entityKind */.i] = "SQLiteAsyncDialect"; async migrate(migrations, session, config) { const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations"; const migrationTableCreate = (0,sql/* sql */.ll)` CREATE TABLE IF NOT EXISTS ${sql/* sql */.ll.identifier(migrationsTable)} ( id SERIAL PRIMARY KEY, hash text NOT NULL, created_at numeric ) `; await session.run(migrationTableCreate); const dbMigrations = await session.values( (0,sql/* sql */.ll)`SELECT id, hash, created_at FROM ${sql/* sql */.ll.identifier(migrationsTable)} ORDER BY created_at DESC LIMIT 1` ); const lastDbMigration = dbMigrations[0] ?? void 0; await session.transaction(async (tx) => { for (const migration of migrations) { if (!lastDbMigration || Number(lastDbMigration[2]) < migration.folderMillis) { for (const stmt of migration.sql) { await tx.run(sql/* sql */.ll.raw(stmt)); } await tx.run( (0,sql/* sql */.ll)`INSERT INTO ${sql/* sql */.ll.identifier(migrationsTable)} ("hash", "created_at") VALUES(${migration.hash}, ${migration.folderMillis})` ); } } }); } } //# sourceMappingURL=dialect.js.map // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-builders/query-builder.js var query_builder = __webpack_require__(6685); // EXTERNAL MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/query-promise.js var query_promise = __webpack_require__(4579); ;// CONCATENATED MODULE: ../../node_modules/.pnpm/drizzle-orm@0.36.4_@libsql+client@0.14.0_@types+better-sqlite3@7.6.13_@types+react@18.3.28_be_bhyfo6jtf7gmzt2fsdpal3g2vq/node_modules/drizzle-orm/sqlite-core/query-builders/select.js class SQLiteSelectBuilder { static [entity/* entityKind */.i] = "SQLiteSelectBuilder"; fields; session; dialect; withList; distinct; constructor(config) { this.fields = config.fields; this.session = config.session; this.dialect = config.dialect; this.withList = config.withList; this.distinct = config.distinct; } from(source) { const isPartialSelect = !!this.fields; let fields; if (this.fields) { fields = this.fields; } else if ((0,entity.is)(source, subquery/* Subquery */.n)) { fields = Object.fromEntries( Object.keys(source._.selectedFields).map((key) => [key, source[key]]) ); } else if ((0,entity.is)(source, SQLiteViewBase)) { fields = source[view_common/* ViewBaseConfig */.n].selectedFields; } else if ((0,entity.is)(source, sql/* SQL */.Xs)) { fields = {}; } else { fields = (0,utils/* getTableColumns */.YD)(source); } return new SQLiteSelectBase({ table: source, fields, isPartialSelect, session: this.session, dialect: this.dialect, withList: this.withList, distinct: this.distinct }); } } class SQLiteSelectQueryBuilderBase extends query_builder/* TypedQueryBuilder */.O { static [entity/* entityKind */.i] = "SQLiteSelectQueryBuilder"; _; /** @internal */ config; joinsNotNullableMap; tableName; isPartialSelect; session; dialect; constructor({ table, fields, isPartialSelect, session, dialect, withList, distinct }) { super(); this.config = { withList, table, fields: { ...fields }, distinct, setOperators: [] }; this.isPartialSelect = isPartialSelect; this.session = session; this.dialect = dialect; this._ = { selectedFields: fields }; this.tableName = (0,utils/* getTableLikeName */.zN)(table); this.joinsNotNullableMap = typeof this.tableName === "string" ? { [this.tableName]: true } : {}; } createJoin(joinType) { return (table, on) => { const baseTableName = this.tableName; const tableName = (0,utils/* getTableLikeName */.zN)(table); if (typeof tableName === "string" && this.config.joins?.some((join) => join.alias === tableName)) { throw new Error(`Alias "${tableName}" is already used in this query`); } if (!this.isPartialSelect) { if (Object.keys(this.joinsNotNullableMap).length === 1 && typeof baseTableName === "string") { this.config.fields = { [baseTableName]: this.config.fields }; } if (typeof tableName === "string" && !(0,entity.is)(table, sql/* SQL */.Xs)) { const selection = (0,entity.is)(table, subquery/* Subquery */.n) ? table._.selectedFields : (0,entity.is)(table, sql/* View */.Ss) ? table[view_common/* ViewBaseConfig */.n].selectedFields : table[drizzle_orm_table/* Table */.XI.Symbol.Columns]; this.config.fields[tableName] = selection; } } if (typeof on === "function") { on = on( new Proxy( this.config.fields, new selection_proxy/* SelectionProxyHandler */.b({ sqlAliasedBehavior: "sql", sqlBehavior: "sql" }) ) ); } if (!this.config.joins) { this.config.joins = []; } this.config.joins.push({ on, table, joinType, alias: tableName }); if (typeof tableName === "string") { switch (joinType) { case "left": { this.joinsNotNullableMap[tableName] = false; break; } case "right": { this.joinsNotNullableMap = Object.fromEntries( Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]) ); this.joinsNotNullableMap[tableName] = true; break; } case "inner": { this.joinsNotNullableMap[tableName] = true; break; } case "full": { this.joinsNotNullableMap = Object.fromEntries( Object.entries(this.joinsNotNullableMap).map(([key]) => [key, false]) ); this.joinsNotNullableMap[tableName] = false; break; } } } return this; }; } /** * Executes a `left join` operation by adding another table to the current query. * * Calling this method associates each row of the table with the corresponding row from the joined table, if a match is found. If no matching row exists, it sets all columns of the joined table to null. * * See docs: {@link https://orm.drizzle.team/docs/joins#left-join} * * @param table the table to join. * @param on the `on` clause. * * @example * * ```ts * // Select all users and their pets * const usersWithPets: { user: User; pets: Pet | null }[] = await db.select() * .from(users) * .leftJoin(pets, eq(users.id, pets.ownerId)) * * // Select userId and petId * const usersIdsAndPetIds: { userId: number; petId: number | null }[] = await db.select({ * userId: users.id, * petId: pets.id, * }) * .from(users) * .leftJoin(pets, eq(users.id, pets.ownerId)) * ``` */ leftJoin = this.createJoin("left"); /** * Executes a `right join` operation by adding another table to the current query. * * Calling this method associates each row of the joined table with the corresponding row from the main table, if a match is found. If no matching row exists, it sets all columns of the main table to null. * * See docs: {@link https://orm.drizzle.team/docs/joins#right-join} * * @param table the table to join. * @param on the `on` clause. * * @example * * ```ts * // Select all users and their pets * const usersWithPets: { user: User | null; pets: Pet }[] = await db.select() * .from(users) * .rightJoin(pets, eq(users.id, pets.ownerId)) * * // Select userId and petId * const usersIdsAndPetIds: { userId: number | null; petId: number }[] = await db.select({ * userId: users.id, * petId: pets.id, * }) * .from(users) * .rightJoin(pets, eq(users.id, pets.ownerId)) * ``` */ rightJoin = this.createJoin("right"); /** * Executes an `inner join` operation, creating a new table by combining rows from two tables that have matching values. * * Calling this method retrieves rows that have corresponding entries in both joined tables. Rows without matching entries in either table are excluded, resulting in a table that includes only matching pairs. * * See docs: {@link https://orm.drizzle.team/docs/joins#inner-join} * * @param table the table to join. * @param on the `on` clause. * * @example * * ```ts * // Select all users and their pets * const usersWithPets: { user: User; pets: Pet }[] = await db.select() * .from(users) * .innerJoin(pets, eq(users.id, pets.ownerId)) * * // Select userId and petId * const usersIdsAndPetIds: { userId: number; petId: number }[] = await db.select({ * userId: users.id, * petId: pets.id, * }) * .from(users) * .innerJoin(pets, eq(users.id, pets.ownerId)) * ``` */ innerJoin = this.createJoin("inner"); /** * Executes a `full join` operation by combining rows from two tables into a new table. * * Calling this method retrieves all rows from both main and joined tables, merging rows with matching values and filling in `null` for non-matching columns. * * See docs: {@link https://orm.drizzle.team/docs/joins#full-join} * * @param table the table to join. * @param on the `on` clause. * * @example * * ```ts * // Select all users and their pets * const usersWithPets: { user: User | null; pets: Pet | null }[] = await db.select() * .from(users) * .fullJoin(pets, eq(users.id, pets.ownerId)) * * // Select userId and petId * const usersIdsAndPetIds: { userId: number | null; petId: number | null }[] = await db.select({ * userId: users.id, * petId: pets.id, * }) * .from(users) * .fullJoin(pets, eq(users.id, pets.ownerId)) * ``` */ fullJoin = this.createJoin("full"); createSetOperator(type, isAll) { return (rightSelection) => { const rightSelect = typeof rightSelection === "function" ? rightSelection(getSQLiteSetOperators()) : rightSelection; if (!(0,utils/* haveSameKeys */.DV)(this.getSelectedFields(), rightSelect.getSelectedFields())) { throw new Error( "Set operator error (union / intersect / except): selected fields are not the same or are in a different order" ); } this.config.setOperators.push({ type, isAll, rightSelect }); return this; }; } /** * Adds `union` set operator to the query. * * Calling this method will combine the result sets of the `select` statements and remove any duplicate rows that appear across them. * * See docs: {@link https://orm.drizzle.team/docs/set-operations#union} * * @example * * ```ts * // Select all unique names from customers and users tables * await db.select({ name: users.name }) * .from(users) * .union( * db.select({ name: customer