drizzle-orm 0.44.7-7cb6516 → 0.45.0-82993ae

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.
Files changed (53) hide show
  1. package/gel-core/dialect.cjs +10 -0
  2. package/gel-core/dialect.cjs.map +1 -1
  3. package/gel-core/dialect.js +10 -0
  4. package/gel-core/dialect.js.map +1 -1
  5. package/mysql-core/dialect.cjs +10 -0
  6. package/mysql-core/dialect.cjs.map +1 -1
  7. package/mysql-core/dialect.js +10 -0
  8. package/mysql-core/dialect.js.map +1 -1
  9. package/mysql-core/indexes.cjs +2 -2
  10. package/mysql-core/indexes.cjs.map +1 -1
  11. package/mysql-core/indexes.d.cts +3 -3
  12. package/mysql-core/indexes.d.ts +3 -3
  13. package/mysql-core/indexes.js +2 -2
  14. package/mysql-core/indexes.js.map +1 -1
  15. package/node-postgres/session.cjs +3 -2
  16. package/node-postgres/session.cjs.map +1 -1
  17. package/node-postgres/session.js +3 -2
  18. package/node-postgres/session.js.map +1 -1
  19. package/operations.cjs.map +1 -1
  20. package/operations.d.cts +3 -2
  21. package/operations.d.ts +3 -2
  22. package/package.json +1 -1
  23. package/pg-core/dialect.cjs +10 -0
  24. package/pg-core/dialect.cjs.map +1 -1
  25. package/pg-core/dialect.js +10 -0
  26. package/pg-core/dialect.js.map +1 -1
  27. package/query-builders/select.types.cjs.map +1 -1
  28. package/query-builders/select.types.d.cts +4 -4
  29. package/query-builders/select.types.d.ts +4 -4
  30. package/singlestore-core/dialect.cjs +10 -0
  31. package/singlestore-core/dialect.cjs.map +1 -1
  32. package/singlestore-core/dialect.js +10 -0
  33. package/singlestore-core/dialect.js.map +1 -1
  34. package/singlestore-core/indexes.cjs +2 -2
  35. package/singlestore-core/indexes.cjs.map +1 -1
  36. package/singlestore-core/indexes.d.cts +3 -3
  37. package/singlestore-core/indexes.d.ts +3 -3
  38. package/singlestore-core/indexes.js +2 -2
  39. package/singlestore-core/indexes.js.map +1 -1
  40. package/sqlite-core/dialect.cjs +11 -0
  41. package/sqlite-core/dialect.cjs.map +1 -1
  42. package/sqlite-core/dialect.js +11 -0
  43. package/sqlite-core/dialect.js.map +1 -1
  44. package/utils.cjs +3 -1
  45. package/utils.cjs.map +1 -1
  46. package/utils.d.cts +5 -0
  47. package/utils.d.ts +5 -0
  48. package/utils.js +3 -1
  49. package/utils.js.map +1 -1
  50. package/version.cjs +1 -1
  51. package/version.d.cts +1 -1
  52. package/version.d.ts +1 -1
  53. package/version.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/dialect.ts"],"sourcesContent":["import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tgetOperators,\n\tgetOrderByOperators,\n\tMany,\n\tnormalizeRelation,\n\tOne,\n\ttype Relation,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { and, eq } from '~/sql/expressions/index.ts';\nimport type { Name, Placeholder, QueryWithTypings, SQLChunk } from '~/sql/sql.ts';\nimport { Param, SQL, sql, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport { SingleStoreColumn } from './columns/common.ts';\nimport type { SingleStoreDeleteConfig } from './query-builders/delete.ts';\nimport type { SingleStoreInsertConfig } from './query-builders/insert.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SingleStoreUpdateConfig } from './query-builders/update.ts';\nimport type { SingleStoreSession } from './session.ts';\nimport { SingleStoreTable } from './table.ts';\n/* import { SingleStoreViewBase } from './view-base.ts'; */\n\nexport interface SingleStoreDialectConfig {\n\tcasing?: Casing;\n}\n\nexport class SingleStoreDialect {\n\tstatic readonly [entityKind]: string = 'SingleStoreDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SingleStoreDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SingleStoreSession,\n\t\tconfig: Omit<MigrationConfig, 'migrationsSchema'>,\n\t): Promise<void> {\n\t\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\t\tconst migrationTableCreate = sql`\n\t\t\tcreate table if not exists ${sql.identifier(migrationsTable)} (\n\t\t\t\tid serial primary key,\n\t\t\t\thash text not null,\n\t\t\t\tcreated_at bigint\n\t\t\t)\n\t\t`;\n\t\tawait session.execute(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0];\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (\n\t\t\t\t\t!lastDbMigration\n\t\t\t\t\t|| Number(lastDbMigration.created_at) < migration.folderMillis\n\t\t\t\t) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.execute(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.execute(\n\t\t\t\t\t\tsql`insert into ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\\`hash\\`, \\`created_at\\`) values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\\`${name}\\``;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn `?`;\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SingleStoreDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\tbuildUpdateSet(table: SingleStoreTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, limit, orderBy }: SingleStoreUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, SingleStoreColumn)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SingleStoreColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\treturn orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tlockingClause,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SingleStoreSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SingleStoreColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t/* : is(table, SingleStoreViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name */\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = (() => {\n\t\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t\t}\n\n\t\t\treturn table;\n\t\t})();\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\t\t\t\tconst lateralSql = joinMeta.lateral ? sql` lateral` : undefined;\n\t\t\t\tconst onSql = joinMeta.on ? sql` on ${joinMeta.on}` : undefined;\n\n\t\t\t\tif (is(table, SingleStoreTable)) {\n\t\t\t\t\tconst tableName = table[SingleStoreTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SingleStoreTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SingleStoreTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\ttableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else if (is(table, View)) {\n\t\t\t\t\tconst viewName = table[ViewBaseConfig].name;\n\t\t\t\t\tconst viewSchema = table[ViewBaseConfig].schema;\n\t\t\t\t\tconst origViewName = table[ViewBaseConfig].originalName;\n\t\t\t\t\tconst alias = viewName === origViewName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\tviewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst joinsSql = sql.join(joinsArray);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : undefined;\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tlet lockingClausesSql;\n\t\tif (lockingClause) {\n\t\t\tconst { config, strength } = lockingClause;\n\t\t\tlockingClausesSql = sql` for ${sql.raw(strength)}`;\n\t\t\tif (config.noWait) {\n\t\t\t\tlockingClausesSql.append(sql` nowait`);\n\t\t\t} else if (config.skipLocked) {\n\t\t\t\tlockingClausesSql.append(sql` skip locked`);\n\t\t\t}\n\t\t}\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SingleStoreSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SingleStoreSelectConfig['setOperators'][number] }): SQL {\n\t\tconst leftChunk = sql`(${leftSelect.getSQL()}) `;\n\t\tconst rightChunk = sql`(${rightSelect.getSQL()})`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid SingleStore syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const orderByUnit of orderBy) {\n\t\t\t\tif (is(orderByUnit, SingleStoreColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(this.casing.getColumnCasing(orderByUnit)));\n\t\t\t\t} else if (is(orderByUnit, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < orderByUnit.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = orderByUnit.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SingleStoreColumn)) {\n\t\t\t\t\t\t\torderByUnit.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values, ignore, onConflict }: SingleStoreInsertConfig,\n\t): { sql: SQL; generatedIds: Record<string, unknown>[] } {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SingleStoreColumn> = table[Table.Symbol.Columns];\n\t\tconst colEntries: [string, SingleStoreColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\t\tconst generatedIdsResponse: Record<string, unknown>[] = [];\n\n\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\tconst generatedIds: Record<string, unknown> = {};\n\n\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\tif (col.defaultFn !== undefined) {\n\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\tgeneratedIds[fieldName] = defaultFnResult;\n\t\t\t\t\t\tconst defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\tconst newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\tvalueList.push(newValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(sql`default`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (col.defaultFn && is(colValue, Param)) {\n\t\t\t\t\t\tgeneratedIds[fieldName] = colValue.value;\n\t\t\t\t\t}\n\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgeneratedIdsResponse.push(generatedIds);\n\t\t\tvaluesSqlList.push(valueList);\n\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t}\n\t\t}\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst ignoreSql = ignore ? sql` ignore` : undefined;\n\n\t\tconst onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;\n\n\t\treturn {\n\t\t\tsql: sql`insert${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`,\n\t\t\tgeneratedIds: generatedIdsResponse,\n\t\t};\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\tbuildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SingleStoreTable;\n\t\ttableConfig: TableRelationalConfig;\n\t\tqueryConfig: true | DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: Relation;\n\t\tjoinOn?: SQL;\n\t}): BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn> {\n\t\tlet selection: BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SingleStoreSelectConfig['orderBy'], where;\n\t\tconst joins: SingleStoreSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SingleStoreColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SingleStoreColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SingleStoreColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | DBQueryConfig<'many', false>;\n\t\t\t\trelation: Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SingleStoreColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this.buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SingleStoreTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);\n\t\t\t\tjoins.push({\n\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({ message: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")` });\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`JSON_TO_ARRAY(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, Many)) {\n\t\t\t\tfield = sql`json_agg(${field})`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || (orderBy?.length ?? 0) > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(((orderBy?.length ?? 0) > 0)\n\t\t\t\t\t\t\t? [{\n\t\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\t\tfield: sql`row_number() over (order by ${sql.join(orderBy!, sql`, `)})`,\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SingleStoreTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwG;AACxG,oBAA4B;AAC5B,oBAAuB;AACvB,oBAA+B;AAC/B,oBAA6B;AAE7B,uBAWO;AACP,yBAAwB;AAExB,iBAAsC;AACtC,sBAAyB;AACzB,mBAAwD;AACxD,mBAAiE;AACjE,yBAA+B;AAC/B,oBAAkC;AAUlC,IAAAA,gBAAiC;AAO1B,MAAM,mBAAmB;AAAA,EAC/B,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAG9B;AAAA,EAET,YAAY,QAAmC;AAC9C,SAAK,SAAS,IAAI,0BAAY,QAAQ,MAAM;AAAA,EAC7C;AAAA,EAEA,MAAM,QACL,YACA,SACA,QACgB;AAChB,UAAM,kBAAkB,OAAO,mBAAmB;AAClD,UAAM,uBAAuB;AAAA,gCACC,eAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,UAAM,QAAQ,QAAQ,oBAAoB;AAE1C,UAAM,eAAe,MAAM,QAAQ;AAAA,MAClC,kDAAuC,eAAI,WAAW,eAAe,CAAC;AAAA,IACvE;AAEA,UAAM,kBAAkB,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A,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,YAAY,YAAY;AAAA,MACxB,KAAK;AAAA,MACL;AAAA,IACD;AAAA,EACD;AACD;","names":["import_table","table","sql","joinOn","field"]}
1
+ {"version":3,"sources":["../../src/singlestore-core/dialect.ts"],"sourcesContent":["import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tgetOperators,\n\tgetOrderByOperators,\n\tMany,\n\tnormalizeRelation,\n\tOne,\n\ttype Relation,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { and, eq } from '~/sql/expressions/index.ts';\nimport type { Name, Placeholder, QueryWithTypings, SQLChunk } from '~/sql/sql.ts';\nimport { Param, SQL, sql, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport { SingleStoreColumn } from './columns/common.ts';\nimport type { SingleStoreDeleteConfig } from './query-builders/delete.ts';\nimport type { SingleStoreInsertConfig } from './query-builders/insert.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SingleStoreUpdateConfig } from './query-builders/update.ts';\nimport type { SingleStoreSession } from './session.ts';\nimport { SingleStoreTable } from './table.ts';\n/* import { SingleStoreViewBase } from './view-base.ts'; */\n\nexport interface SingleStoreDialectConfig {\n\tcasing?: Casing;\n}\n\nexport class SingleStoreDialect {\n\tstatic readonly [entityKind]: string = 'SingleStoreDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SingleStoreDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SingleStoreSession,\n\t\tconfig: Omit<MigrationConfig, 'migrationsSchema'>,\n\t): Promise<void> {\n\t\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\t\tconst migrationTableCreate = sql`\n\t\t\tcreate table if not exists ${sql.identifier(migrationsTable)} (\n\t\t\t\tid serial primary key,\n\t\t\t\thash text not null,\n\t\t\t\tcreated_at bigint\n\t\t\t)\n\t\t`;\n\t\tawait session.execute(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0];\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (\n\t\t\t\t\t!lastDbMigration\n\t\t\t\t\t|| Number(lastDbMigration.created_at) < migration.folderMillis\n\t\t\t\t) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.execute(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.execute(\n\t\t\t\t\t\tsql`insert into ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\\`hash\\`, \\`created_at\\`) values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\\`${name}\\``;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn `?`;\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SingleStoreDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\tbuildUpdateSet(table: SingleStoreTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, limit, orderBy }: SingleStoreUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, SingleStoreColumn)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(field);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Subquery)) {\n\t\t\t\t\tconst entries = Object.entries(field._.selectedFields) as [string, SQL.Aliased | Column | SQL][];\n\n\t\t\t\t\tif (entries.length === 1) {\n\t\t\t\t\t\tconst entry = entries[0]![1];\n\n\t\t\t\t\t\tconst fieldDecoder = is(entry, SQL)\n\t\t\t\t\t\t\t? entry.decoder\n\t\t\t\t\t\t\t: is(entry, Column)\n\t\t\t\t\t\t\t? { mapFromDriverValue: (v: any) => entry.mapFromDriverValue(v) }\n\t\t\t\t\t\t\t: entry.sql.decoder;\n\n\t\t\t\t\t\tif (fieldDecoder) {\n\t\t\t\t\t\t\tfield._.sql.decoder = fieldDecoder;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchunk.push(field);\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SingleStoreColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\treturn orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tlockingClause,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SingleStoreSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SingleStoreColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t/* : is(table, SingleStoreViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name */\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = (() => {\n\t\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t\t}\n\n\t\t\treturn table;\n\t\t})();\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\t\t\t\tconst lateralSql = joinMeta.lateral ? sql` lateral` : undefined;\n\t\t\t\tconst onSql = joinMeta.on ? sql` on ${joinMeta.on}` : undefined;\n\n\t\t\t\tif (is(table, SingleStoreTable)) {\n\t\t\t\t\tconst tableName = table[SingleStoreTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SingleStoreTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SingleStoreTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\ttableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else if (is(table, View)) {\n\t\t\t\t\tconst viewName = table[ViewBaseConfig].name;\n\t\t\t\t\tconst viewSchema = table[ViewBaseConfig].schema;\n\t\t\t\t\tconst origViewName = table[ViewBaseConfig].originalName;\n\t\t\t\t\tconst alias = viewName === origViewName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\tviewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst joinsSql = sql.join(joinsArray);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : undefined;\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tlet lockingClausesSql;\n\t\tif (lockingClause) {\n\t\t\tconst { config, strength } = lockingClause;\n\t\t\tlockingClausesSql = sql` for ${sql.raw(strength)}`;\n\t\t\tif (config.noWait) {\n\t\t\t\tlockingClausesSql.append(sql` nowait`);\n\t\t\t} else if (config.skipLocked) {\n\t\t\t\tlockingClausesSql.append(sql` skip locked`);\n\t\t\t}\n\t\t}\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SingleStoreSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SingleStoreSelectConfig['setOperators'][number] }): SQL {\n\t\tconst leftChunk = sql`(${leftSelect.getSQL()}) `;\n\t\tconst rightChunk = sql`(${rightSelect.getSQL()})`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid SingleStore syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const orderByUnit of orderBy) {\n\t\t\t\tif (is(orderByUnit, SingleStoreColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(this.casing.getColumnCasing(orderByUnit)));\n\t\t\t\t} else if (is(orderByUnit, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < orderByUnit.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = orderByUnit.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SingleStoreColumn)) {\n\t\t\t\t\t\t\torderByUnit.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values, ignore, onConflict }: SingleStoreInsertConfig,\n\t): { sql: SQL; generatedIds: Record<string, unknown>[] } {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SingleStoreColumn> = table[Table.Symbol.Columns];\n\t\tconst colEntries: [string, SingleStoreColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\t\tconst generatedIdsResponse: Record<string, unknown>[] = [];\n\n\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\tconst generatedIds: Record<string, unknown> = {};\n\n\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\tif (col.defaultFn !== undefined) {\n\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\tgeneratedIds[fieldName] = defaultFnResult;\n\t\t\t\t\t\tconst defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\tconst newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\tvalueList.push(newValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(sql`default`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (col.defaultFn && is(colValue, Param)) {\n\t\t\t\t\t\tgeneratedIds[fieldName] = colValue.value;\n\t\t\t\t\t}\n\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgeneratedIdsResponse.push(generatedIds);\n\t\t\tvaluesSqlList.push(valueList);\n\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t}\n\t\t}\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst ignoreSql = ignore ? sql` ignore` : undefined;\n\n\t\tconst onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;\n\n\t\treturn {\n\t\t\tsql: sql`insert${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`,\n\t\t\tgeneratedIds: generatedIdsResponse,\n\t\t};\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\tbuildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SingleStoreTable;\n\t\ttableConfig: TableRelationalConfig;\n\t\tqueryConfig: true | DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: Relation;\n\t\tjoinOn?: SQL;\n\t}): BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn> {\n\t\tlet selection: BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SingleStoreSelectConfig['orderBy'], where;\n\t\tconst joins: SingleStoreSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SingleStoreColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SingleStoreColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SingleStoreColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | DBQueryConfig<'many', false>;\n\t\t\t\trelation: Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SingleStoreColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this.buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SingleStoreTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);\n\t\t\t\tjoins.push({\n\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({ message: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")` });\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`JSON_TO_ARRAY(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, Many)) {\n\t\t\t\tfield = sql`json_agg(${field})`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || (orderBy?.length ?? 0) > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(((orderBy?.length ?? 0) > 0)\n\t\t\t\t\t\t\t? [{\n\t\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\t\tfield: sql`row_number() over (order by ${sql.join(orderBy!, sql`, `)})`,\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SingleStoreTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,mBAAwG;AACxG,oBAA4B;AAC5B,oBAAuB;AACvB,oBAA+B;AAC/B,oBAA6B;AAE7B,uBAWO;AACP,yBAAwB;AAExB,iBAAsC;AACtC,sBAAyB;AACzB,mBAAwD;AACxD,mBAAiE;AACjE,yBAA+B;AAC/B,oBAAkC;AAUlC,IAAAA,gBAAiC;AAO1B,MAAM,mBAAmB;AAAA,EAC/B,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAG9B;AAAA,EAET,YAAY,QAAmC;AAC9C,SAAK,SAAS,IAAI,0BAAY,QAAQ,MAAM;AAA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eAAS,KAAK,iBAAiB;AAAA,QAC9B,WAAO,kBAAG,QAAQ,8BAAgB,IAAI,SAAS,IAAI,yBAAS,QAAQ,CAAC,GAAG,UAAU;AAAA,QAClF,QAAQ,CAAC;AAAA,QACT,YAAY,gBAAgB,IAAI,CAAC,EAAE,OAAAA,OAAM,OAAO;AAAA,UAC/C,MAAM,CAAC;AAAA,UACP,WAAO,kBAAGA,QAAO,oBAAM,QAAI,iCAAmBA,QAAO,UAAU,IAAIA;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF,OAAO;AACN,eAAS,KAAK,iBAAiB;AAAA,QAC9B,WAAO,2BAAa,OAAO,UAAU;AAAA,QACrC,QAAQ,CAAC;AAAA,QACT,YAAY,UAAU,IAAI,CAAC,EAAE,MAAM,OAAO;AAAA,UACzC,MAAM,CAAC;AAAA,UACP,WAAO,kBAAG,OAAO,oBAAM,QAAI,iCAAmB,OAAO,UAAU,IAAI;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,YAAY,YAAY;AAAA,MACxB,KAAK;AAAA,MACL;AAAA,IACD;AAAA,EACD;AACD;","names":["import_table","table","sql","joinOn","field"]}
@@ -148,6 +148,16 @@ class SingleStoreDialect {
148
148
  } else {
149
149
  chunk.push(field);
150
150
  }
151
+ } else if (is(field, Subquery)) {
152
+ const entries = Object.entries(field._.selectedFields);
153
+ if (entries.length === 1) {
154
+ const entry = entries[0][1];
155
+ const fieldDecoder = is(entry, SQL) ? entry.decoder : is(entry, Column) ? { mapFromDriverValue: (v) => entry.mapFromDriverValue(v) } : entry.sql.decoder;
156
+ if (fieldDecoder) {
157
+ field._.sql.decoder = fieldDecoder;
158
+ }
159
+ }
160
+ chunk.push(field);
151
161
  }
152
162
  if (i < columnsLen - 1) {
153
163
  chunk.push(sql`, `);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/dialect.ts"],"sourcesContent":["import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tgetOperators,\n\tgetOrderByOperators,\n\tMany,\n\tnormalizeRelation,\n\tOne,\n\ttype Relation,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { and, eq } from '~/sql/expressions/index.ts';\nimport type { Name, Placeholder, QueryWithTypings, SQLChunk } from '~/sql/sql.ts';\nimport { Param, SQL, sql, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport { SingleStoreColumn } from './columns/common.ts';\nimport type { SingleStoreDeleteConfig } from './query-builders/delete.ts';\nimport type { SingleStoreInsertConfig } from './query-builders/insert.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SingleStoreUpdateConfig } from './query-builders/update.ts';\nimport type { SingleStoreSession } from './session.ts';\nimport { SingleStoreTable } from './table.ts';\n/* import { SingleStoreViewBase } from './view-base.ts'; */\n\nexport interface SingleStoreDialectConfig {\n\tcasing?: Casing;\n}\n\nexport class SingleStoreDialect {\n\tstatic readonly [entityKind]: string = 'SingleStoreDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SingleStoreDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SingleStoreSession,\n\t\tconfig: Omit<MigrationConfig, 'migrationsSchema'>,\n\t): Promise<void> {\n\t\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\t\tconst migrationTableCreate = sql`\n\t\t\tcreate table if not exists ${sql.identifier(migrationsTable)} (\n\t\t\t\tid serial primary key,\n\t\t\t\thash text not null,\n\t\t\t\tcreated_at bigint\n\t\t\t)\n\t\t`;\n\t\tawait session.execute(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0];\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (\n\t\t\t\t\t!lastDbMigration\n\t\t\t\t\t|| Number(lastDbMigration.created_at) < migration.folderMillis\n\t\t\t\t) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.execute(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.execute(\n\t\t\t\t\t\tsql`insert into ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\\`hash\\`, \\`created_at\\`) values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\\`${name}\\``;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn `?`;\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SingleStoreDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\tbuildUpdateSet(table: SingleStoreTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, limit, orderBy }: SingleStoreUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, SingleStoreColumn)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SingleStoreColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\treturn orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tlockingClause,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SingleStoreSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SingleStoreColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t/* : is(table, SingleStoreViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name */\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = (() => {\n\t\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t\t}\n\n\t\t\treturn table;\n\t\t})();\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\t\t\t\tconst lateralSql = joinMeta.lateral ? sql` lateral` : undefined;\n\t\t\t\tconst onSql = joinMeta.on ? sql` on ${joinMeta.on}` : undefined;\n\n\t\t\t\tif (is(table, SingleStoreTable)) {\n\t\t\t\t\tconst tableName = table[SingleStoreTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SingleStoreTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SingleStoreTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\ttableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else if (is(table, View)) {\n\t\t\t\t\tconst viewName = table[ViewBaseConfig].name;\n\t\t\t\t\tconst viewSchema = table[ViewBaseConfig].schema;\n\t\t\t\t\tconst origViewName = table[ViewBaseConfig].originalName;\n\t\t\t\t\tconst alias = viewName === origViewName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\tviewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst joinsSql = sql.join(joinsArray);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : undefined;\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tlet lockingClausesSql;\n\t\tif (lockingClause) {\n\t\t\tconst { config, strength } = lockingClause;\n\t\t\tlockingClausesSql = sql` for ${sql.raw(strength)}`;\n\t\t\tif (config.noWait) {\n\t\t\t\tlockingClausesSql.append(sql` nowait`);\n\t\t\t} else if (config.skipLocked) {\n\t\t\t\tlockingClausesSql.append(sql` skip locked`);\n\t\t\t}\n\t\t}\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SingleStoreSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SingleStoreSelectConfig['setOperators'][number] }): SQL {\n\t\tconst leftChunk = sql`(${leftSelect.getSQL()}) `;\n\t\tconst rightChunk = sql`(${rightSelect.getSQL()})`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid SingleStore syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const orderByUnit of orderBy) {\n\t\t\t\tif (is(orderByUnit, SingleStoreColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(this.casing.getColumnCasing(orderByUnit)));\n\t\t\t\t} else if (is(orderByUnit, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < orderByUnit.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = orderByUnit.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SingleStoreColumn)) {\n\t\t\t\t\t\t\torderByUnit.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values, ignore, onConflict }: SingleStoreInsertConfig,\n\t): { sql: SQL; generatedIds: Record<string, unknown>[] } {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SingleStoreColumn> = table[Table.Symbol.Columns];\n\t\tconst colEntries: [string, SingleStoreColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\t\tconst generatedIdsResponse: Record<string, unknown>[] = [];\n\n\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\tconst generatedIds: Record<string, unknown> = {};\n\n\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\tif (col.defaultFn !== undefined) {\n\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\tgeneratedIds[fieldName] = defaultFnResult;\n\t\t\t\t\t\tconst defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\tconst newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\tvalueList.push(newValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(sql`default`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (col.defaultFn && is(colValue, Param)) {\n\t\t\t\t\t\tgeneratedIds[fieldName] = colValue.value;\n\t\t\t\t\t}\n\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgeneratedIdsResponse.push(generatedIds);\n\t\t\tvaluesSqlList.push(valueList);\n\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t}\n\t\t}\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst ignoreSql = ignore ? sql` ignore` : undefined;\n\n\t\tconst onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;\n\n\t\treturn {\n\t\t\tsql: sql`insert${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`,\n\t\t\tgeneratedIds: generatedIdsResponse,\n\t\t};\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\tbuildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SingleStoreTable;\n\t\ttableConfig: TableRelationalConfig;\n\t\tqueryConfig: true | DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: Relation;\n\t\tjoinOn?: SQL;\n\t}): BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn> {\n\t\tlet selection: BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SingleStoreSelectConfig['orderBy'], where;\n\t\tconst joins: SingleStoreSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SingleStoreColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SingleStoreColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SingleStoreColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | DBQueryConfig<'many', false>;\n\t\t\t\trelation: Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SingleStoreColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this.buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SingleStoreTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);\n\t\t\t\tjoins.push({\n\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({ message: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")` });\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`JSON_TO_ARRAY(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, Many)) {\n\t\t\t\tfield = sql`json_agg(${field})`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || (orderBy?.length ?? 0) > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(((orderBy?.length ?? 0) > 0)\n\t\t\t\t\t\t\t? [{\n\t\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\t\tfield: sql`row_number() over (order by ${sql.join(orderBy!, sql`, `)})`,\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SingleStoreTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n}\n"],"mappings":"AAAA,SAAS,cAAc,oBAAoB,+BAA+B,8BAA8B;AACxG,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,YAAY,UAAU;AAC/B,SAAS,oBAAoB;AAE7B;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,KAAK,UAAU;AAExB,SAAS,OAAO,KAAK,KAAK,YAAY;AACtC,SAAS,gBAAgB;AACzB,SAAS,cAAc,oBAAoB,aAAa;AACxD,SAAsB,2BAA2C;AACjE,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAUlC,SAAS,wBAAwB;AAO1B,MAAM,mBAAmB;AAAA,EAC/B,QAAiB,UAAU,IAAY;AAAA;AAAA,EAG9B;AAAA,EAET,YAAY,QAAmC;AAC9C,SAAK,SAAS,IAAI,YAAY,QAAQ,MAAM;AAAA,EAC7C;AAAA,EAEA,MAAM,QACL,YACA,SACA,QACgB;AAChB,UAAM,kBAAkB,OAAO,mBAAmB;AAClD,UAAM,uBAAuB;AAAA,gCACC,IAAI,WAAW,eAAe,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAM7D,UAAM,QAAQ,QAAQ,oBAAoB;AAE1C,UAAM,eAAe,MAAM,QAAQ;AAAA,MAClC,uCAAuC,IAAI,WAAW,eAAe,CAAC;AAAA,IACvE;AAEA,UAAM,kBAAkB,aAAa,CAAC;AAEtC,UAAM,QAAQ,YAAY,OAAO,OAAO;AACvC,iBAAW,aAAa,YAAY;AACnC,YACC,CAAC,mBACE,OAAO,gBAAgB,UA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;AAAA,YACrE,CAAC,IACC,CAAC;AAAA,UACL;AAAA,UACA;AAAA,UACA;AAAA,UACA;AAAA,UACA,cAAc,CAAC;AAAA,QAChB,CAAC;AAED,gBAAQ;AACR,gBAAQ;AACR,iBAAS;AACT,kBAAU;AAAA,MACX,OAAO;AACN,iBAAS,aAAa,OAAO,UAAU;AAAA,MACxC;AAEA,eAAS,KAAK,iBAAiB;AAAA,QAC9B,OAAO,GAAG,QAAQ,gBAAgB,IAAI,SAAS,IAAI,SAAS,QAAQ,CAAC,GAAG,UAAU;AAAA,QAClF,QAAQ,CAAC;AAAA,QACT,YAAY,gBAAgB,IAAI,CAAC,EAAE,OAAAA,OAAM,OAAO;AAAA,UAC/C,MAAM,CAAC;AAAA,UACP,OAAO,GAAGA,QAAO,MAAM,IAAI,mBAAmBA,QAAO,UAAU,IAAIA;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF,OAAO;AACN,eAAS,KAAK,iBAAiB;AAAA,QAC9B,OAAO,aAAa,OAAO,UAAU;AAAA,QACrC,QAAQ,CAAC;AAAA,QACT,YAAY,UAAU,IAAI,CAAC,EAAE,MAAM,OAAO;AAAA,UACzC,MAAM,CAAC;AAAA,UACP,OAAO,GAAG,OAAO,MAAM,IAAI,mBAAmB,OAAO,UAAU,IAAI;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,YAAY,YAAY;AAAA,MACxB,KAAK;AAAA,MACL;AAAA,IACD;AAAA,EACD;AACD;","names":["table","sql","joinOn","field"]}
1
+ {"version":3,"sources":["../../src/singlestore-core/dialect.ts"],"sourcesContent":["import { aliasedTable, aliasedTableColumn, mapColumnsInAliasedSQLToAlias, mapColumnsInSQLToAlias } from '~/alias.ts';\nimport { CasingCache } from '~/casing.ts';\nimport { Column } from '~/column.ts';\nimport { entityKind, is } from '~/entity.ts';\nimport { DrizzleError } from '~/errors.ts';\nimport type { MigrationConfig, MigrationMeta } from '~/migrator.ts';\nimport {\n\ttype BuildRelationalQueryResult,\n\ttype DBQueryConfig,\n\tgetOperators,\n\tgetOrderByOperators,\n\tMany,\n\tnormalizeRelation,\n\tOne,\n\ttype Relation,\n\ttype TableRelationalConfig,\n\ttype TablesRelationalConfig,\n} from '~/relations.ts';\nimport { and, eq } from '~/sql/expressions/index.ts';\nimport type { Name, Placeholder, QueryWithTypings, SQLChunk } from '~/sql/sql.ts';\nimport { Param, SQL, sql, View } from '~/sql/sql.ts';\nimport { Subquery } from '~/subquery.ts';\nimport { getTableName, getTableUniqueName, Table } from '~/table.ts';\nimport { type Casing, orderSelectedFields, type UpdateSet } from '~/utils.ts';\nimport { ViewBaseConfig } from '~/view-common.ts';\nimport { SingleStoreColumn } from './columns/common.ts';\nimport type { SingleStoreDeleteConfig } from './query-builders/delete.ts';\nimport type { SingleStoreInsertConfig } from './query-builders/insert.ts';\nimport type {\n\tSelectedFieldsOrdered,\n\tSingleStoreSelectConfig,\n\tSingleStoreSelectJoinConfig,\n} from './query-builders/select.types.ts';\nimport type { SingleStoreUpdateConfig } from './query-builders/update.ts';\nimport type { SingleStoreSession } from './session.ts';\nimport { SingleStoreTable } from './table.ts';\n/* import { SingleStoreViewBase } from './view-base.ts'; */\n\nexport interface SingleStoreDialectConfig {\n\tcasing?: Casing;\n}\n\nexport class SingleStoreDialect {\n\tstatic readonly [entityKind]: string = 'SingleStoreDialect';\n\n\t/** @internal */\n\treadonly casing: CasingCache;\n\n\tconstructor(config?: SingleStoreDialectConfig) {\n\t\tthis.casing = new CasingCache(config?.casing);\n\t}\n\n\tasync migrate(\n\t\tmigrations: MigrationMeta[],\n\t\tsession: SingleStoreSession,\n\t\tconfig: Omit<MigrationConfig, 'migrationsSchema'>,\n\t): Promise<void> {\n\t\tconst migrationsTable = config.migrationsTable ?? '__drizzle_migrations';\n\t\tconst migrationTableCreate = sql`\n\t\t\tcreate table if not exists ${sql.identifier(migrationsTable)} (\n\t\t\t\tid serial primary key,\n\t\t\t\thash text not null,\n\t\t\t\tcreated_at bigint\n\t\t\t)\n\t\t`;\n\t\tawait session.execute(migrationTableCreate);\n\n\t\tconst dbMigrations = await session.all<{ id: number; hash: string; created_at: string }>(\n\t\t\tsql`select id, hash, created_at from ${sql.identifier(migrationsTable)} order by created_at desc limit 1`,\n\t\t);\n\n\t\tconst lastDbMigration = dbMigrations[0];\n\n\t\tawait session.transaction(async (tx) => {\n\t\t\tfor (const migration of migrations) {\n\t\t\t\tif (\n\t\t\t\t\t!lastDbMigration\n\t\t\t\t\t|| Number(lastDbMigration.created_at) < migration.folderMillis\n\t\t\t\t) {\n\t\t\t\t\tfor (const stmt of migration.sql) {\n\t\t\t\t\t\tawait tx.execute(sql.raw(stmt));\n\t\t\t\t\t}\n\t\t\t\t\tawait tx.execute(\n\t\t\t\t\t\tsql`insert into ${\n\t\t\t\t\t\t\tsql.identifier(migrationsTable)\n\t\t\t\t\t\t} (\\`hash\\`, \\`created_at\\`) values(${migration.hash}, ${migration.folderMillis})`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n\n\tescapeName(name: string): string {\n\t\treturn `\\`${name}\\``;\n\t}\n\n\tescapeParam(_num: number): string {\n\t\treturn `?`;\n\t}\n\n\tescapeString(str: string): string {\n\t\treturn `'${str.replace(/'/g, \"''\")}'`;\n\t}\n\n\tprivate buildWithCTE(queries: Subquery[] | undefined): SQL | undefined {\n\t\tif (!queries?.length) return undefined;\n\n\t\tconst withSqlChunks = [sql`with `];\n\t\tfor (const [i, w] of queries.entries()) {\n\t\t\twithSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);\n\t\t\tif (i < queries.length - 1) {\n\t\t\t\twithSqlChunks.push(sql`, `);\n\t\t\t}\n\t\t}\n\t\twithSqlChunks.push(sql` `);\n\t\treturn sql.join(withSqlChunks);\n\t}\n\n\tbuildDeleteQuery({ table, where, returning, withList, limit, orderBy }: SingleStoreDeleteConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}delete from ${table}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\tbuildUpdateSet(table: SingleStoreTable, set: UpdateSet): SQL {\n\t\tconst tableColumns = table[Table.Symbol.Columns];\n\n\t\tconst columnNames = Object.keys(tableColumns).filter((colName) =>\n\t\t\tset[colName] !== undefined || tableColumns[colName]?.onUpdateFn !== undefined\n\t\t);\n\n\t\tconst setSize = columnNames.length;\n\t\treturn sql.join(columnNames.flatMap((colName, i) => {\n\t\t\tconst col = tableColumns[colName]!;\n\n\t\t\tconst value = set[colName] ?? sql.param(col.onUpdateFn!(), col);\n\t\t\tconst res = sql`${sql.identifier(this.casing.getColumnCasing(col))} = ${value}`;\n\n\t\t\tif (i < setSize - 1) {\n\t\t\t\treturn [res, sql.raw(', ')];\n\t\t\t}\n\t\t\treturn [res];\n\t\t}));\n\t}\n\n\tbuildUpdateQuery({ table, set, where, returning, withList, limit, orderBy }: SingleStoreUpdateConfig): SQL {\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst setSql = this.buildUpdateSet(table, set);\n\n\t\tconst returningSql = returning\n\t\t\t? sql` returning ${this.buildSelection(returning, { isSingleTable: true })}`\n\t\t\t: undefined;\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\treturn sql`${withSql}update ${table} set ${setSql}${whereSql}${orderBySql}${limitSql}${returningSql}`;\n\t}\n\n\t/**\n\t * Builds selection SQL with provided fields/expressions\n\t *\n\t * Examples:\n\t *\n\t * `select <selection> from`\n\t *\n\t * `insert ... returning <selection>`\n\t *\n\t * If `isSingleTable` is true, then columns won't be prefixed with table name\n\t */\n\tprivate buildSelection(\n\t\tfields: SelectedFieldsOrdered,\n\t\t{ isSingleTable = false }: { isSingleTable?: boolean } = {},\n\t): SQL {\n\t\tconst columnsLen = fields.length;\n\n\t\tconst chunks = fields\n\t\t\t.flatMap(({ field }, i) => {\n\t\t\t\tconst chunk: SQLChunk[] = [];\n\n\t\t\t\tif (is(field, SQL.Aliased) && field.isSelectionField) {\n\t\t\t\t\tchunk.push(sql.identifier(field.fieldAlias));\n\t\t\t\t} else if (is(field, SQL.Aliased) || is(field, SQL)) {\n\t\t\t\t\tconst query = is(field, SQL.Aliased) ? field.sql : field;\n\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(\n\t\t\t\t\t\t\tnew SQL(\n\t\t\t\t\t\t\t\tquery.queryChunks.map((c) => {\n\t\t\t\t\t\t\t\t\tif (is(c, SingleStoreColumn)) {\n\t\t\t\t\t\t\t\t\t\treturn sql.identifier(this.casing.getColumnCasing(c));\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn c;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(query);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (is(field, SQL.Aliased)) {\n\t\t\t\t\t\tchunk.push(sql` as ${sql.identifier(field.fieldAlias)}`);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Column)) {\n\t\t\t\t\tif (isSingleTable) {\n\t\t\t\t\t\tchunk.push(sql.identifier(this.casing.getColumnCasing(field)));\n\t\t\t\t\t} else {\n\t\t\t\t\t\tchunk.push(field);\n\t\t\t\t\t}\n\t\t\t\t} else if (is(field, Subquery)) {\n\t\t\t\t\tconst entries = Object.entries(field._.selectedFields) as [string, SQL.Aliased | Column | SQL][];\n\n\t\t\t\t\tif (entries.length === 1) {\n\t\t\t\t\t\tconst entry = entries[0]![1];\n\n\t\t\t\t\t\tconst fieldDecoder = is(entry, SQL)\n\t\t\t\t\t\t\t? entry.decoder\n\t\t\t\t\t\t\t: is(entry, Column)\n\t\t\t\t\t\t\t? { mapFromDriverValue: (v: any) => entry.mapFromDriverValue(v) }\n\t\t\t\t\t\t\t: entry.sql.decoder;\n\n\t\t\t\t\t\tif (fieldDecoder) {\n\t\t\t\t\t\t\tfield._.sql.decoder = fieldDecoder;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tchunk.push(field);\n\t\t\t\t}\n\n\t\t\t\tif (i < columnsLen - 1) {\n\t\t\t\t\tchunk.push(sql`, `);\n\t\t\t\t}\n\n\t\t\t\treturn chunk;\n\t\t\t});\n\n\t\treturn sql.join(chunks);\n\t}\n\n\tprivate buildLimit(limit: number | Placeholder | undefined): SQL | undefined {\n\t\treturn typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\t}\n\n\tprivate buildOrderBy(orderBy: (SingleStoreColumn | SQL | SQL.Aliased)[] | undefined): SQL | undefined {\n\t\treturn orderBy && orderBy.length > 0 ? sql` order by ${sql.join(orderBy, sql`, `)}` : undefined;\n\t}\n\n\tbuildSelectQuery(\n\t\t{\n\t\t\twithList,\n\t\t\tfields,\n\t\t\tfieldsFlat,\n\t\t\twhere,\n\t\t\thaving,\n\t\t\ttable,\n\t\t\tjoins,\n\t\t\torderBy,\n\t\t\tgroupBy,\n\t\t\tlimit,\n\t\t\toffset,\n\t\t\tlockingClause,\n\t\t\tdistinct,\n\t\t\tsetOperators,\n\t\t}: SingleStoreSelectConfig,\n\t): SQL {\n\t\tconst fieldsList = fieldsFlat ?? orderSelectedFields<SingleStoreColumn>(fields);\n\t\tfor (const f of fieldsList) {\n\t\t\tif (\n\t\t\t\tis(f.field, Column)\n\t\t\t\t&& getTableName(f.field.table)\n\t\t\t\t\t!== (is(table, Subquery)\n\t\t\t\t\t\t? table._.alias\n\t\t\t\t\t\t/* : is(table, SingleStoreViewBase)\n\t\t\t\t\t\t? table[ViewBaseConfig].name */\n\t\t\t\t\t\t: is(table, SQL)\n\t\t\t\t\t\t? undefined\n\t\t\t\t\t\t: getTableName(table))\n\t\t\t\t&& !((table) =>\n\t\t\t\t\tjoins?.some(({ alias }) =>\n\t\t\t\t\t\talias === (table[Table.Symbol.IsAlias] ? getTableName(table) : table[Table.Symbol.BaseName])\n\t\t\t\t\t))(f.field.table)\n\t\t\t) {\n\t\t\t\tconst tableName = getTableName(f.field.table);\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Your \"${\n\t\t\t\t\t\tf.path.join('->')\n\t\t\t\t\t}\" field references a column \"${tableName}\".\"${f.field.name}\", but the table \"${tableName}\" is not part of the query! Did you forget to join it?`,\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\n\t\tconst isSingleTable = !joins || joins.length === 0;\n\n\t\tconst withSql = this.buildWithCTE(withList);\n\n\t\tconst distinctSql = distinct ? sql` distinct` : undefined;\n\n\t\tconst selection = this.buildSelection(fieldsList, { isSingleTable });\n\n\t\tconst tableSql = (() => {\n\t\t\tif (is(table, Table) && table[Table.Symbol.IsAlias]) {\n\t\t\t\treturn sql`${sql`${sql.identifier(table[Table.Symbol.Schema] ?? '')}.`.if(table[Table.Symbol.Schema])}${\n\t\t\t\t\tsql.identifier(table[Table.Symbol.OriginalName])\n\t\t\t\t} ${sql.identifier(table[Table.Symbol.Name])}`;\n\t\t\t}\n\n\t\t\treturn table;\n\t\t})();\n\n\t\tconst joinsArray: SQL[] = [];\n\n\t\tif (joins) {\n\t\t\tfor (const [index, joinMeta] of joins.entries()) {\n\t\t\t\tif (index === 0) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t\tconst table = joinMeta.table;\n\t\t\t\tconst lateralSql = joinMeta.lateral ? sql` lateral` : undefined;\n\t\t\t\tconst onSql = joinMeta.on ? sql` on ${joinMeta.on}` : undefined;\n\n\t\t\t\tif (is(table, SingleStoreTable)) {\n\t\t\t\t\tconst tableName = table[SingleStoreTable.Symbol.Name];\n\t\t\t\t\tconst tableSchema = table[SingleStoreTable.Symbol.Schema];\n\t\t\t\t\tconst origTableName = table[SingleStoreTable.Symbol.OriginalName];\n\t\t\t\t\tconst alias = tableName === origTableName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\ttableSchema ? sql`${sql.identifier(tableSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origTableName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else if (is(table, View)) {\n\t\t\t\t\tconst viewName = table[ViewBaseConfig].name;\n\t\t\t\t\tconst viewSchema = table[ViewBaseConfig].schema;\n\t\t\t\t\tconst origViewName = table[ViewBaseConfig].originalName;\n\t\t\t\t\tconst alias = viewName === origViewName ? undefined : joinMeta.alias;\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${\n\t\t\t\t\t\t\tviewSchema ? sql`${sql.identifier(viewSchema)}.` : undefined\n\t\t\t\t\t\t}${sql.identifier(origViewName)}${alias && sql` ${sql.identifier(alias)}`}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t} else {\n\t\t\t\t\tjoinsArray.push(\n\t\t\t\t\t\tsql`${sql.raw(joinMeta.joinType)} join${lateralSql} ${table}${onSql}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t\tif (index < joins.length - 1) {\n\t\t\t\t\tjoinsArray.push(sql` `);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tconst joinsSql = sql.join(joinsArray);\n\n\t\tconst whereSql = where ? sql` where ${where}` : undefined;\n\n\t\tconst havingSql = having ? sql` having ${having}` : undefined;\n\n\t\tconst orderBySql = this.buildOrderBy(orderBy);\n\n\t\tconst groupBySql = groupBy && groupBy.length > 0 ? sql` group by ${sql.join(groupBy, sql`, `)}` : undefined;\n\n\t\tconst limitSql = this.buildLimit(limit);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\tlet lockingClausesSql;\n\t\tif (lockingClause) {\n\t\t\tconst { config, strength } = lockingClause;\n\t\t\tlockingClausesSql = sql` for ${sql.raw(strength)}`;\n\t\t\tif (config.noWait) {\n\t\t\t\tlockingClausesSql.append(sql` nowait`);\n\t\t\t} else if (config.skipLocked) {\n\t\t\t\tlockingClausesSql.append(sql` skip locked`);\n\t\t\t}\n\t\t}\n\n\t\tconst finalQuery =\n\t\t\tsql`${withSql}select${distinctSql} ${selection} from ${tableSql}${joinsSql}${whereSql}${groupBySql}${havingSql}${orderBySql}${limitSql}${offsetSql}${lockingClausesSql}`;\n\n\t\tif (setOperators.length > 0) {\n\t\t\treturn this.buildSetOperations(finalQuery, setOperators);\n\t\t}\n\n\t\treturn finalQuery;\n\t}\n\n\tbuildSetOperations(leftSelect: SQL, setOperators: SingleStoreSelectConfig['setOperators']): SQL {\n\t\tconst [setOperator, ...rest] = setOperators;\n\n\t\tif (!setOperator) {\n\t\t\tthrow new Error('Cannot pass undefined values to any set operator');\n\t\t}\n\n\t\tif (rest.length === 0) {\n\t\t\treturn this.buildSetOperationQuery({ leftSelect, setOperator });\n\t\t}\n\n\t\t// Some recursive magic here\n\t\treturn this.buildSetOperations(\n\t\t\tthis.buildSetOperationQuery({ leftSelect, setOperator }),\n\t\t\trest,\n\t\t);\n\t}\n\n\tbuildSetOperationQuery({\n\t\tleftSelect,\n\t\tsetOperator: { type, isAll, rightSelect, limit, orderBy, offset },\n\t}: { leftSelect: SQL; setOperator: SingleStoreSelectConfig['setOperators'][number] }): SQL {\n\t\tconst leftChunk = sql`(${leftSelect.getSQL()}) `;\n\t\tconst rightChunk = sql`(${rightSelect.getSQL()})`;\n\n\t\tlet orderBySql;\n\t\tif (orderBy && orderBy.length > 0) {\n\t\t\tconst orderByValues: (SQL<unknown> | Name)[] = [];\n\n\t\t\t// The next bit is necessary because the sql operator replaces ${table.column} with `table`.`column`\n\t\t\t// which is invalid SingleStore syntax, Table from one of the SELECTs cannot be used in global ORDER clause\n\t\t\tfor (const orderByUnit of orderBy) {\n\t\t\t\tif (is(orderByUnit, SingleStoreColumn)) {\n\t\t\t\t\torderByValues.push(sql.identifier(this.casing.getColumnCasing(orderByUnit)));\n\t\t\t\t} else if (is(orderByUnit, SQL)) {\n\t\t\t\t\tfor (let i = 0; i < orderByUnit.queryChunks.length; i++) {\n\t\t\t\t\t\tconst chunk = orderByUnit.queryChunks[i];\n\n\t\t\t\t\t\tif (is(chunk, SingleStoreColumn)) {\n\t\t\t\t\t\t\torderByUnit.queryChunks[i] = sql.identifier(this.casing.getColumnCasing(chunk));\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t} else {\n\t\t\t\t\torderByValues.push(sql`${orderByUnit}`);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\torderBySql = sql` order by ${sql.join(orderByValues, sql`, `)} `;\n\t\t}\n\n\t\tconst limitSql = typeof limit === 'object' || (typeof limit === 'number' && limit >= 0)\n\t\t\t? sql` limit ${limit}`\n\t\t\t: undefined;\n\n\t\tconst operatorChunk = sql.raw(`${type} ${isAll ? 'all ' : ''}`);\n\n\t\tconst offsetSql = offset ? sql` offset ${offset}` : undefined;\n\n\t\treturn sql`${leftChunk}${operatorChunk}${rightChunk}${orderBySql}${limitSql}${offsetSql}`;\n\t}\n\n\tbuildInsertQuery(\n\t\t{ table, values, ignore, onConflict }: SingleStoreInsertConfig,\n\t): { sql: SQL; generatedIds: Record<string, unknown>[] } {\n\t\t// const isSingleValue = values.length === 1;\n\t\tconst valuesSqlList: ((SQLChunk | SQL)[] | SQL)[] = [];\n\t\tconst columns: Record<string, SingleStoreColumn> = table[Table.Symbol.Columns];\n\t\tconst colEntries: [string, SingleStoreColumn][] = Object.entries(columns).filter(([_, col]) =>\n\t\t\t!col.shouldDisableInsert()\n\t\t);\n\n\t\tconst insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));\n\t\tconst generatedIdsResponse: Record<string, unknown>[] = [];\n\n\t\tfor (const [valueIndex, value] of values.entries()) {\n\t\t\tconst generatedIds: Record<string, unknown> = {};\n\n\t\t\tconst valueList: (SQLChunk | SQL)[] = [];\n\t\t\tfor (const [fieldName, col] of colEntries) {\n\t\t\t\tconst colValue = value[fieldName];\n\t\t\t\tif (colValue === undefined || (is(colValue, Param) && colValue.value === undefined)) {\n\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\tif (col.defaultFn !== undefined) {\n\t\t\t\t\t\tconst defaultFnResult = col.defaultFn();\n\t\t\t\t\t\tgeneratedIds[fieldName] = defaultFnResult;\n\t\t\t\t\t\tconst defaultValue = is(defaultFnResult, SQL) ? defaultFnResult : sql.param(defaultFnResult, col);\n\t\t\t\t\t\tvalueList.push(defaultValue);\n\t\t\t\t\t\t// eslint-disable-next-line unicorn/no-negated-condition\n\t\t\t\t\t} else if (!col.default && col.onUpdateFn !== undefined) {\n\t\t\t\t\t\tconst onUpdateFnResult = col.onUpdateFn();\n\t\t\t\t\t\tconst newValue = is(onUpdateFnResult, SQL) ? onUpdateFnResult : sql.param(onUpdateFnResult, col);\n\t\t\t\t\t\tvalueList.push(newValue);\n\t\t\t\t\t} else {\n\t\t\t\t\t\tvalueList.push(sql`default`);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif (col.defaultFn && is(colValue, Param)) {\n\t\t\t\t\t\tgeneratedIds[fieldName] = colValue.value;\n\t\t\t\t\t}\n\t\t\t\t\tvalueList.push(colValue);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tgeneratedIdsResponse.push(generatedIds);\n\t\t\tvaluesSqlList.push(valueList);\n\t\t\tif (valueIndex < values.length - 1) {\n\t\t\t\tvaluesSqlList.push(sql`, `);\n\t\t\t}\n\t\t}\n\n\t\tconst valuesSql = sql.join(valuesSqlList);\n\n\t\tconst ignoreSql = ignore ? sql` ignore` : undefined;\n\n\t\tconst onConflictSql = onConflict ? sql` on duplicate key ${onConflict}` : undefined;\n\n\t\treturn {\n\t\t\tsql: sql`insert${ignoreSql} into ${table} ${insertOrder} values ${valuesSql}${onConflictSql}`,\n\t\t\tgeneratedIds: generatedIdsResponse,\n\t\t};\n\t}\n\n\tsqlToQuery(sql: SQL, invokeSource?: 'indexes' | undefined): QueryWithTypings {\n\t\treturn sql.toQuery({\n\t\t\tcasing: this.casing,\n\t\t\tescapeName: this.escapeName,\n\t\t\tescapeParam: this.escapeParam,\n\t\t\tescapeString: this.escapeString,\n\t\t\tinvokeSource,\n\t\t});\n\t}\n\n\tbuildRelationalQuery({\n\t\tfullSchema,\n\t\tschema,\n\t\ttableNamesMap,\n\t\ttable,\n\t\ttableConfig,\n\t\tqueryConfig: config,\n\t\ttableAlias,\n\t\tnestedQueryRelation,\n\t\tjoinOn,\n\t}: {\n\t\tfullSchema: Record<string, unknown>;\n\t\tschema: TablesRelationalConfig;\n\t\ttableNamesMap: Record<string, string>;\n\t\ttable: SingleStoreTable;\n\t\ttableConfig: TableRelationalConfig;\n\t\tqueryConfig: true | DBQueryConfig<'many', true>;\n\t\ttableAlias: string;\n\t\tnestedQueryRelation?: Relation;\n\t\tjoinOn?: SQL;\n\t}): BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn> {\n\t\tlet selection: BuildRelationalQueryResult<SingleStoreTable, SingleStoreColumn>['selection'] = [];\n\t\tlet limit, offset, orderBy: SingleStoreSelectConfig['orderBy'], where;\n\t\tconst joins: SingleStoreSelectJoinConfig[] = [];\n\n\t\tif (config === true) {\n\t\t\tconst selectionEntries = Object.entries(tableConfig.columns);\n\t\t\tselection = selectionEntries.map((\n\t\t\t\t[key, value],\n\t\t\t) => ({\n\t\t\t\tdbKey: value.name,\n\t\t\t\ttsKey: key,\n\t\t\t\tfield: aliasedTableColumn(value as SingleStoreColumn, tableAlias),\n\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\tisJson: false,\n\t\t\t\tselection: [],\n\t\t\t}));\n\t\t} else {\n\t\t\tconst aliasedColumns = Object.fromEntries(\n\t\t\t\tObject.entries(tableConfig.columns).map(([key, value]) => [key, aliasedTableColumn(value, tableAlias)]),\n\t\t\t);\n\n\t\t\tif (config.where) {\n\t\t\t\tconst whereSql = typeof config.where === 'function'\n\t\t\t\t\t? config.where(aliasedColumns, getOperators())\n\t\t\t\t\t: config.where;\n\t\t\t\twhere = whereSql && mapColumnsInSQLToAlias(whereSql, tableAlias);\n\t\t\t}\n\n\t\t\tconst fieldsSelection: { tsKey: string; value: SingleStoreColumn | SQL.Aliased }[] = [];\n\t\t\tlet selectedColumns: string[] = [];\n\n\t\t\t// Figure out which columns to select\n\t\t\tif (config.columns) {\n\t\t\t\tlet isIncludeMode = false;\n\n\t\t\t\tfor (const [field, value] of Object.entries(config.columns)) {\n\t\t\t\t\tif (value === undefined) {\n\t\t\t\t\t\tcontinue;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (field in tableConfig.columns) {\n\t\t\t\t\t\tif (!isIncludeMode && value === true) {\n\t\t\t\t\t\t\tisIncludeMode = true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tselectedColumns.push(field);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tif (selectedColumns.length > 0) {\n\t\t\t\t\tselectedColumns = isIncludeMode\n\t\t\t\t\t\t? selectedColumns.filter((c) => config.columns?.[c] === true)\n\t\t\t\t\t\t: Object.keys(tableConfig.columns).filter((key) => !selectedColumns.includes(key));\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\t// Select all columns if selection is not specified\n\t\t\t\tselectedColumns = Object.keys(tableConfig.columns);\n\t\t\t}\n\n\t\t\tfor (const field of selectedColumns) {\n\t\t\t\tconst column = tableConfig.columns[field]! as SingleStoreColumn;\n\t\t\t\tfieldsSelection.push({ tsKey: field, value: column });\n\t\t\t}\n\n\t\t\tlet selectedRelations: {\n\t\t\t\ttsKey: string;\n\t\t\t\tqueryConfig: true | DBQueryConfig<'many', false>;\n\t\t\t\trelation: Relation;\n\t\t\t}[] = [];\n\n\t\t\t// Figure out which relations to select\n\t\t\tif (config.with) {\n\t\t\t\tselectedRelations = Object.entries(config.with)\n\t\t\t\t\t.filter((entry): entry is [typeof entry[0], NonNullable<typeof entry[1]>] => !!entry[1])\n\t\t\t\t\t.map(([tsKey, queryConfig]) => ({ tsKey, queryConfig, relation: tableConfig.relations[tsKey]! }));\n\t\t\t}\n\n\t\t\tlet extras;\n\n\t\t\t// Figure out which extras to select\n\t\t\tif (config.extras) {\n\t\t\t\textras = typeof config.extras === 'function'\n\t\t\t\t\t? config.extras(aliasedColumns, { sql })\n\t\t\t\t\t: config.extras;\n\t\t\t\tfor (const [tsKey, value] of Object.entries(extras)) {\n\t\t\t\t\tfieldsSelection.push({\n\t\t\t\t\t\ttsKey,\n\t\t\t\t\t\tvalue: mapColumnsInAliasedSQLToAlias(value, tableAlias),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Transform `fieldsSelection` into `selection`\n\t\t\t// `fieldsSelection` shouldn't be used after this point\n\t\t\tfor (const { tsKey, value } of fieldsSelection) {\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: is(value, SQL.Aliased) ? value.fieldAlias : tableConfig.columns[tsKey]!.name,\n\t\t\t\t\ttsKey,\n\t\t\t\t\tfield: is(value, Column) ? aliasedTableColumn(value, tableAlias) : value,\n\t\t\t\t\trelationTableTsKey: undefined,\n\t\t\t\t\tisJson: false,\n\t\t\t\t\tselection: [],\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tlet orderByOrig = typeof config.orderBy === 'function'\n\t\t\t\t? config.orderBy(aliasedColumns, getOrderByOperators())\n\t\t\t\t: config.orderBy ?? [];\n\t\t\tif (!Array.isArray(orderByOrig)) {\n\t\t\t\torderByOrig = [orderByOrig];\n\t\t\t}\n\t\t\torderBy = orderByOrig.map((orderByValue) => {\n\t\t\t\tif (is(orderByValue, Column)) {\n\t\t\t\t\treturn aliasedTableColumn(orderByValue, tableAlias) as SingleStoreColumn;\n\t\t\t\t}\n\t\t\t\treturn mapColumnsInSQLToAlias(orderByValue, tableAlias);\n\t\t\t});\n\n\t\t\tlimit = config.limit;\n\t\t\toffset = config.offset;\n\n\t\t\t// Process all relations\n\t\t\tfor (\n\t\t\t\tconst {\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tqueryConfig: selectedRelationConfigValue,\n\t\t\t\t\trelation,\n\t\t\t\t} of selectedRelations\n\t\t\t) {\n\t\t\t\tconst normalizedRelation = normalizeRelation(schema, tableNamesMap, relation);\n\t\t\t\tconst relationTableName = getTableUniqueName(relation.referencedTable);\n\t\t\t\tconst relationTableTsName = tableNamesMap[relationTableName]!;\n\t\t\t\tconst relationTableAlias = `${tableAlias}_${selectedRelationTsKey}`;\n\t\t\t\tconst joinOn = and(\n\t\t\t\t\t...normalizedRelation.fields.map((field, i) =>\n\t\t\t\t\t\teq(\n\t\t\t\t\t\t\taliasedTableColumn(normalizedRelation.references[i]!, relationTableAlias),\n\t\t\t\t\t\t\taliasedTableColumn(field, tableAlias),\n\t\t\t\t\t\t)\n\t\t\t\t\t),\n\t\t\t\t);\n\t\t\t\tconst builtRelation = this.buildRelationalQuery({\n\t\t\t\t\tfullSchema,\n\t\t\t\t\tschema,\n\t\t\t\t\ttableNamesMap,\n\t\t\t\t\ttable: fullSchema[relationTableTsName] as SingleStoreTable,\n\t\t\t\t\ttableConfig: schema[relationTableTsName]!,\n\t\t\t\t\tqueryConfig: is(relation, One)\n\t\t\t\t\t\t? (selectedRelationConfigValue === true\n\t\t\t\t\t\t\t? { limit: 1 }\n\t\t\t\t\t\t\t: { ...selectedRelationConfigValue, limit: 1 })\n\t\t\t\t\t\t: selectedRelationConfigValue,\n\t\t\t\t\ttableAlias: relationTableAlias,\n\t\t\t\t\tjoinOn,\n\t\t\t\t\tnestedQueryRelation: relation,\n\t\t\t\t});\n\t\t\t\tconst field = sql`${sql.identifier(relationTableAlias)}.${sql.identifier('data')}`.as(selectedRelationTsKey);\n\t\t\t\tjoins.push({\n\t\t\t\t\ton: sql`true`,\n\t\t\t\t\ttable: new Subquery(builtRelation.sql as SQL, {}, relationTableAlias),\n\t\t\t\t\talias: relationTableAlias,\n\t\t\t\t\tjoinType: 'left',\n\t\t\t\t\tlateral: true,\n\t\t\t\t});\n\t\t\t\tselection.push({\n\t\t\t\t\tdbKey: selectedRelationTsKey,\n\t\t\t\t\ttsKey: selectedRelationTsKey,\n\t\t\t\t\tfield,\n\t\t\t\t\trelationTableTsKey: relationTableTsName,\n\t\t\t\t\tisJson: true,\n\t\t\t\t\tselection: builtRelation.selection,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tif (selection.length === 0) {\n\t\t\tthrow new DrizzleError({ message: `No fields selected for table \"${tableConfig.tsName}\" (\"${tableAlias}\")` });\n\t\t}\n\n\t\tlet result;\n\n\t\twhere = and(joinOn, where);\n\n\t\tif (nestedQueryRelation) {\n\t\t\tlet field = sql`JSON_TO_ARRAY(${\n\t\t\t\tsql.join(\n\t\t\t\t\tselection.map(({ field, tsKey, isJson }) =>\n\t\t\t\t\t\tisJson\n\t\t\t\t\t\t\t? sql`${sql.identifier(`${tableAlias}_${tsKey}`)}.${sql.identifier('data')}`\n\t\t\t\t\t\t\t: is(field, SQL.Aliased)\n\t\t\t\t\t\t\t? field.sql\n\t\t\t\t\t\t\t: field\n\t\t\t\t\t),\n\t\t\t\t\tsql`, `,\n\t\t\t\t)\n\t\t\t})`;\n\t\t\tif (is(nestedQueryRelation, Many)) {\n\t\t\t\tfield = sql`json_agg(${field})`;\n\t\t\t}\n\t\t\tconst nestedSelection = [{\n\t\t\t\tdbKey: 'data',\n\t\t\t\ttsKey: 'data',\n\t\t\t\tfield: field.as('data'),\n\t\t\t\tisJson: true,\n\t\t\t\trelationTableTsKey: tableConfig.tsName,\n\t\t\t\tselection,\n\t\t\t}];\n\n\t\t\tconst needsSubquery = limit !== undefined || offset !== undefined || (orderBy?.length ?? 0) > 0;\n\n\t\t\tif (needsSubquery) {\n\t\t\t\tresult = this.buildSelectQuery({\n\t\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\t\tfields: {},\n\t\t\t\t\tfieldsFlat: [\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\tfield: sql.raw('*'),\n\t\t\t\t\t\t},\n\t\t\t\t\t\t...(((orderBy?.length ?? 0) > 0)\n\t\t\t\t\t\t\t? [{\n\t\t\t\t\t\t\t\tpath: [],\n\t\t\t\t\t\t\t\tfield: sql`row_number() over (order by ${sql.join(orderBy!, sql`, `)})`,\n\t\t\t\t\t\t\t}]\n\t\t\t\t\t\t\t: []),\n\t\t\t\t\t],\n\t\t\t\t\twhere,\n\t\t\t\t\tlimit,\n\t\t\t\t\toffset,\n\t\t\t\t\tsetOperators: [],\n\t\t\t\t});\n\n\t\t\t\twhere = undefined;\n\t\t\t\tlimit = undefined;\n\t\t\t\toffset = undefined;\n\t\t\t\torderBy = undefined;\n\t\t\t} else {\n\t\t\t\tresult = aliasedTable(table, tableAlias);\n\t\t\t}\n\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: is(result, SingleStoreTable) ? result : new Subquery(result, {}, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: nestedSelection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t} else {\n\t\t\tresult = this.buildSelectQuery({\n\t\t\t\ttable: aliasedTable(table, tableAlias),\n\t\t\t\tfields: {},\n\t\t\t\tfieldsFlat: selection.map(({ field }) => ({\n\t\t\t\t\tpath: [],\n\t\t\t\t\tfield: is(field, Column) ? aliasedTableColumn(field, tableAlias) : field,\n\t\t\t\t})),\n\t\t\t\tjoins,\n\t\t\t\twhere,\n\t\t\t\tlimit,\n\t\t\t\toffset,\n\t\t\t\torderBy,\n\t\t\t\tsetOperators: [],\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\ttableTsKey: tableConfig.tsName,\n\t\t\tsql: result,\n\t\t\tselection,\n\t\t};\n\t}\n}\n"],"mappings":"AAAA,SAAS,cAAc,oBAAoB,+BAA+B,8BAA8B;AACxG,SAAS,mBAAmB;AAC5B,SAAS,cAAc;AACvB,SAAS,YAAY,UAAU;AAC/B,SAAS,oBAAoB;AAE7B;AAAA,EAGC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIM;AACP,SAAS,KAAK,UAAU;AAExB,SAAS,OAAO,KAAK,KAAK,YAAY;AACtC,SAAS,gBAAgB;AACzB,SAAS,cAAc,oBAAoB,aAAa;AACxD,SAAsB,2BAA2C;AACjE,SAAS,sBAAsB;AAC/B,SAAS,yBAAyB;AAUlC,SAAS,wBAAwB;AAO1B,MAAM,mBAAmB;AAAA,EAC/B,QAAiB,UAAU,IAAY;AAAA;AAAA,EAG9B;AAAA,EAET,YAAY,QAAmC;AAC9C,SAAK,SAAS,IAAI,YAAY,QAAQ,MAAM;AAAA,EAC7C;AAAA,EAEA,MAAM,QACL,YACA,SACA,QACgB;AAChB,UAAM,kBAAkB,OAAO,mBAAmB;AAClD,UAAM,uBAAuB;AAAA,gCACC,IAAI,WAAW,eAAe,CAAC;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A;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF,OAAO;AACN,eAAS,KAAK,iBAAiB;AAAA,QAC9B,OAAO,aAAa,OAAO,UAAU;AAAA,QACrC,QAAQ,CAAC;AAAA,QACT,YAAY,UAAU,IAAI,CAAC,EAAE,MAAM,OAAO;AAAA,UACzC,MAAM,CAAC;AAAA,UACP,OAAO,GAAG,OAAO,MAAM,IAAI,mBAAmB,OAAO,UAAU,IAAI;AAAA,QACpE,EAAE;AAAA,QACF;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,QACA,cAAc,CAAC;AAAA,MAChB,CAAC;AAAA,IACF;AAEA,WAAO;AAAA,MACN,YAAY,YAAY;AAAA,MACxB,KAAK;AAAA,MACL;AAAA,IACD;AAAA,EACD;AACD;","names":["table","sql","joinOn","field"]}
@@ -51,8 +51,8 @@ class IndexBuilder {
51
51
  this.config.using = using;
52
52
  return this;
53
53
  }
54
- algorythm(algorythm) {
55
- this.config.algorythm = algorythm;
54
+ algorithm(algorithm) {
55
+ this.config.algorithm = algorithm;
56
56
  return this;
57
57
  }
58
58
  lock(lock) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/indexes.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { AnySingleStoreColumn, SingleStoreColumn } from './columns/index.ts';\nimport type { SingleStoreTable } from './table.ts';\n\ninterface IndexConfig {\n\tname: string;\n\n\tcolumns: IndexColumn[];\n\n\t/**\n\t * If true, the index will be created as `create unique index` instead of `create index`.\n\t */\n\tunique?: boolean;\n\n\t/**\n\t * If set, the index will be created as `create index ... using { 'btree' | 'hash' }`.\n\t */\n\tusing?: 'btree' | 'hash';\n\n\t/**\n\t * If set, the index will be created as `create index ... algorythm { 'default' | 'inplace' | 'copy' }`.\n\t */\n\talgorythm?: 'default' | 'inplace' | 'copy';\n\n\t/**\n\t * If set, adds locks to the index creation.\n\t */\n\tlock?: 'default' | 'none' | 'shared' | 'exclusive';\n}\n\nexport type IndexColumn = SingleStoreColumn | SQL;\n\nexport class IndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilderOn';\n\n\tconstructor(private name: string, private unique: boolean) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder {\n\t\treturn new IndexBuilder(this.name, columns, this.unique);\n\t}\n}\n\nexport interface AnyIndexBuilder {\n\tbuild(table: SingleStoreTable): Index;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IndexBuilder extends AnyIndexBuilder {}\n\nexport class IndexBuilder implements AnyIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilder';\n\n\t/** @internal */\n\tconfig: IndexConfig;\n\n\tconstructor(name: string, columns: IndexColumn[], unique: boolean) {\n\t\tthis.config = {\n\t\t\tname,\n\t\t\tcolumns,\n\t\t\tunique,\n\t\t};\n\t}\n\n\tusing(using: IndexConfig['using']): this {\n\t\tthis.config.using = using;\n\t\treturn this;\n\t}\n\n\talgorythm(algorythm: IndexConfig['algorythm']): this {\n\t\tthis.config.algorythm = algorythm;\n\t\treturn this;\n\t}\n\n\tlock(lock: IndexConfig['lock']): this {\n\t\tthis.config.lock = lock;\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tbuild(table: SingleStoreTable): Index {\n\t\treturn new Index(this.config, table);\n\t}\n}\n\nexport class Index {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndex';\n\n\treadonly config: IndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: IndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport type GetColumnsTableName<TColumns> = TColumns extends\n\tAnySingleStoreColumn<{ tableName: infer TTableName extends string }> | AnySingleStoreColumn<\n\t\t{ tableName: infer TTableName extends string }\n\t>[] ? TTableName\n\t: never;\n\nexport function index(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, false);\n}\n\nexport function uniqueIndex(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, true);\n}\n\n/* export interface AnyFullTextIndexBuilder {\n\tbuild(table: SingleStoreTable): FullTextIndex;\n} */\n/*\ninterface FullTextIndexConfig {\n\tversion?: number;\n}\n\ninterface FullTextIndexFullConfig extends FullTextIndexConfig {\n\tcolumns: IndexColumn[];\n\n\tname: string;\n}\n\nexport class FullTextIndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilderOn';\n\n\tconstructor(private name: string, private config: FullTextIndexConfig) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): FullTextIndexBuilder {\n\t\treturn new FullTextIndexBuilder({\n\t\t\tname: this.name,\n\t\t\tcolumns: columns,\n\t\t\t...this.config,\n\t\t});\n\t}\n} */\n\n/*\nexport interface FullTextIndexBuilder extends AnyFullTextIndexBuilder {}\n\nexport class FullTextIndexBuilder implements AnyFullTextIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilder'; */\n\n/** @internal */\n/* config: FullTextIndexFullConfig;\n\n\tconstructor(config: FullTextIndexFullConfig) {\n\t\tthis.config = config;\n\t} */\n\n/** @internal */\n/* build(table: SingleStoreTable): FullTextIndex {\n\t\treturn new FullTextIndex(this.config, table);\n\t}\n}\n\nexport class FullTextIndex {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndex';\n\n\treadonly config: FullTextIndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: FullTextIndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport function fulltext(name: string, config: FullTextIndexConfig): FullTextIndexBuilderOn {\n\treturn new FullTextIndexBuilderOn(name, config);\n}\n\nexport type SortKeyColumn = SingleStoreColumn | SQL;\n\nexport class SortKeyBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKeyBuilder';\n\n\tconstructor(private columns: SortKeyColumn[]) {} */\n\n/** @internal */\n/* build(table: SingleStoreTable): SortKey {\n\t\treturn new SortKey(this.columns, table);\n\t}\n}\n\nexport class SortKey {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKey';\n\n\tconstructor(public columns: SortKeyColumn[], public table: SingleStoreTable) {}\n}\n\nexport function sortKey(...columns: SortKeyColumn[]): SortKeyBuilder {\n\treturn new SortKeyBuilder(columns);\n}\n */\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAiCpB,MAAM,eAAe;AAAA,EAG3B,YAAoB,MAAsB,QAAiB;AAAvC;AAAsB;AAAA,EAAkB;AAAA,EAF5D,QAAiB,wBAAU,IAAY;AAAA,EAIvC,MAAM,SAAwD;AAC7D,WAAO,IAAI,aAAa,KAAK,MAAM,SAAS,KAAK,MAAM;AAAA,EACxD;AACD;AASO,MAAM,aAAwC;AAAA,EACpD,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC;AAAA,EAEA,YAAY,MAAc,SAAwB,QAAiB;AAClE,SAAK,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,OAAmC;AACxC,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAEA,UAAU,WAA2C;AACpD,SAAK,OAAO,YAAY;AACxB,WAAO;AAAA,EACR;AAAA,EAEA,KAAK,MAAiC;AACrC,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,OAAgC;AACrC,WAAO,IAAI,MAAM,KAAK,QAAQ,KAAK;AAAA,EACpC;AACD;AAEO,MAAM,MAAM;AAAA,EAClB,QAAiB,wBAAU,IAAY;AAAA,EAE9B;AAAA,EAET,YAAY,QAAqB,OAAyB;AACzD,SAAK,SAAS,EAAE,GAAG,QAAQ,MAAM;AAAA,EAClC;AACD;AAQO,SAAS,MAAM,MAA8B;AACnD,SAAO,IAAI,eAAe,MAAM,KAAK;AACtC;AAEO,SAAS,YAAY,MAA8B;AACzD,SAAO,IAAI,eAAe,MAAM,IAAI;AACrC;","names":[]}
1
+ {"version":3,"sources":["../../src/singlestore-core/indexes.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { AnySingleStoreColumn, SingleStoreColumn } from './columns/index.ts';\nimport type { SingleStoreTable } from './table.ts';\n\ninterface IndexConfig {\n\tname: string;\n\n\tcolumns: IndexColumn[];\n\n\t/**\n\t * If true, the index will be created as `create unique index` instead of `create index`.\n\t */\n\tunique?: boolean;\n\n\t/**\n\t * If set, the index will be created as `create index ... using { 'btree' | 'hash' }`.\n\t */\n\tusing?: 'btree' | 'hash';\n\n\t/**\n\t * If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.\n\t */\n\talgorithm?: 'default' | 'inplace' | 'copy';\n\n\t/**\n\t * If set, adds locks to the index creation.\n\t */\n\tlock?: 'default' | 'none' | 'shared' | 'exclusive';\n}\n\nexport type IndexColumn = SingleStoreColumn | SQL;\n\nexport class IndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilderOn';\n\n\tconstructor(private name: string, private unique: boolean) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder {\n\t\treturn new IndexBuilder(this.name, columns, this.unique);\n\t}\n}\n\nexport interface AnyIndexBuilder {\n\tbuild(table: SingleStoreTable): Index;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IndexBuilder extends AnyIndexBuilder {}\n\nexport class IndexBuilder implements AnyIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilder';\n\n\t/** @internal */\n\tconfig: IndexConfig;\n\n\tconstructor(name: string, columns: IndexColumn[], unique: boolean) {\n\t\tthis.config = {\n\t\t\tname,\n\t\t\tcolumns,\n\t\t\tunique,\n\t\t};\n\t}\n\n\tusing(using: IndexConfig['using']): this {\n\t\tthis.config.using = using;\n\t\treturn this;\n\t}\n\n\talgorithm(algorithm: IndexConfig['algorithm']): this {\n\t\tthis.config.algorithm = algorithm;\n\t\treturn this;\n\t}\n\n\tlock(lock: IndexConfig['lock']): this {\n\t\tthis.config.lock = lock;\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tbuild(table: SingleStoreTable): Index {\n\t\treturn new Index(this.config, table);\n\t}\n}\n\nexport class Index {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndex';\n\n\treadonly config: IndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: IndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport type GetColumnsTableName<TColumns> = TColumns extends\n\tAnySingleStoreColumn<{ tableName: infer TTableName extends string }> | AnySingleStoreColumn<\n\t\t{ tableName: infer TTableName extends string }\n\t>[] ? TTableName\n\t: never;\n\nexport function index(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, false);\n}\n\nexport function uniqueIndex(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, true);\n}\n\n/* export interface AnyFullTextIndexBuilder {\n\tbuild(table: SingleStoreTable): FullTextIndex;\n} */\n/*\ninterface FullTextIndexConfig {\n\tversion?: number;\n}\n\ninterface FullTextIndexFullConfig extends FullTextIndexConfig {\n\tcolumns: IndexColumn[];\n\n\tname: string;\n}\n\nexport class FullTextIndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilderOn';\n\n\tconstructor(private name: string, private config: FullTextIndexConfig) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): FullTextIndexBuilder {\n\t\treturn new FullTextIndexBuilder({\n\t\t\tname: this.name,\n\t\t\tcolumns: columns,\n\t\t\t...this.config,\n\t\t});\n\t}\n} */\n\n/*\nexport interface FullTextIndexBuilder extends AnyFullTextIndexBuilder {}\n\nexport class FullTextIndexBuilder implements AnyFullTextIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilder'; */\n\n/** @internal */\n/* config: FullTextIndexFullConfig;\n\n\tconstructor(config: FullTextIndexFullConfig) {\n\t\tthis.config = config;\n\t} */\n\n/** @internal */\n/* build(table: SingleStoreTable): FullTextIndex {\n\t\treturn new FullTextIndex(this.config, table);\n\t}\n}\n\nexport class FullTextIndex {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndex';\n\n\treadonly config: FullTextIndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: FullTextIndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport function fulltext(name: string, config: FullTextIndexConfig): FullTextIndexBuilderOn {\n\treturn new FullTextIndexBuilderOn(name, config);\n}\n\nexport type SortKeyColumn = SingleStoreColumn | SQL;\n\nexport class SortKeyBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKeyBuilder';\n\n\tconstructor(private columns: SortKeyColumn[]) {} */\n\n/** @internal */\n/* build(table: SingleStoreTable): SortKey {\n\t\treturn new SortKey(this.columns, table);\n\t}\n}\n\nexport class SortKey {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKey';\n\n\tconstructor(public columns: SortKeyColumn[], public table: SingleStoreTable) {}\n}\n\nexport function sortKey(...columns: SortKeyColumn[]): SortKeyBuilder {\n\treturn new SortKeyBuilder(columns);\n}\n */\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAA2B;AAiCpB,MAAM,eAAe;AAAA,EAG3B,YAAoB,MAAsB,QAAiB;AAAvC;AAAsB;AAAA,EAAkB;AAAA,EAF5D,QAAiB,wBAAU,IAAY;AAAA,EAIvC,MAAM,SAAwD;AAC7D,WAAO,IAAI,aAAa,KAAK,MAAM,SAAS,KAAK,MAAM;AAAA,EACxD;AACD;AASO,MAAM,aAAwC;AAAA,EACpD,QAAiB,wBAAU,IAAY;AAAA;AAAA,EAGvC;AAAA,EAEA,YAAY,MAAc,SAAwB,QAAiB;AAClE,SAAK,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,OAAmC;AACxC,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAEA,UAAU,WAA2C;AACpD,SAAK,OAAO,YAAY;AACxB,WAAO;AAAA,EACR;AAAA,EAEA,KAAK,MAAiC;AACrC,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,OAAgC;AACrC,WAAO,IAAI,MAAM,KAAK,QAAQ,KAAK;AAAA,EACpC;AACD;AAEO,MAAM,MAAM;AAAA,EAClB,QAAiB,wBAAU,IAAY;AAAA,EAE9B;AAAA,EAET,YAAY,QAAqB,OAAyB;AACzD,SAAK,SAAS,EAAE,GAAG,QAAQ,MAAM;AAAA,EAClC;AACD;AAQO,SAAS,MAAM,MAA8B;AACnD,SAAO,IAAI,eAAe,MAAM,KAAK;AACtC;AAEO,SAAS,YAAY,MAA8B;AACzD,SAAO,IAAI,eAAe,MAAM,IAAI;AACrC;","names":[]}
@@ -14,9 +14,9 @@ interface IndexConfig {
14
14
  */
15
15
  using?: 'btree' | 'hash';
16
16
  /**
17
- * If set, the index will be created as `create index ... algorythm { 'default' | 'inplace' | 'copy' }`.
17
+ * If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.
18
18
  */
19
- algorythm?: 'default' | 'inplace' | 'copy';
19
+ algorithm?: 'default' | 'inplace' | 'copy';
20
20
  /**
21
21
  * If set, adds locks to the index creation.
22
22
  */
@@ -39,7 +39,7 @@ export declare class IndexBuilder implements AnyIndexBuilder {
39
39
  static readonly [entityKind]: string;
40
40
  constructor(name: string, columns: IndexColumn[], unique: boolean);
41
41
  using(using: IndexConfig['using']): this;
42
- algorythm(algorythm: IndexConfig['algorythm']): this;
42
+ algorithm(algorithm: IndexConfig['algorithm']): this;
43
43
  lock(lock: IndexConfig['lock']): this;
44
44
  }
45
45
  export declare class Index {
@@ -14,9 +14,9 @@ interface IndexConfig {
14
14
  */
15
15
  using?: 'btree' | 'hash';
16
16
  /**
17
- * If set, the index will be created as `create index ... algorythm { 'default' | 'inplace' | 'copy' }`.
17
+ * If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.
18
18
  */
19
- algorythm?: 'default' | 'inplace' | 'copy';
19
+ algorithm?: 'default' | 'inplace' | 'copy';
20
20
  /**
21
21
  * If set, adds locks to the index creation.
22
22
  */
@@ -39,7 +39,7 @@ export declare class IndexBuilder implements AnyIndexBuilder {
39
39
  static readonly [entityKind]: string;
40
40
  constructor(name: string, columns: IndexColumn[], unique: boolean);
41
41
  using(using: IndexConfig['using']): this;
42
- algorythm(algorythm: IndexConfig['algorythm']): this;
42
+ algorithm(algorithm: IndexConfig['algorithm']): this;
43
43
  lock(lock: IndexConfig['lock']): this;
44
44
  }
45
45
  export declare class Index {
@@ -24,8 +24,8 @@ class IndexBuilder {
24
24
  this.config.using = using;
25
25
  return this;
26
26
  }
27
- algorythm(algorythm) {
28
- this.config.algorythm = algorythm;
27
+ algorithm(algorithm) {
28
+ this.config.algorithm = algorithm;
29
29
  return this;
30
30
  }
31
31
  lock(lock) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/singlestore-core/indexes.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { AnySingleStoreColumn, SingleStoreColumn } from './columns/index.ts';\nimport type { SingleStoreTable } from './table.ts';\n\ninterface IndexConfig {\n\tname: string;\n\n\tcolumns: IndexColumn[];\n\n\t/**\n\t * If true, the index will be created as `create unique index` instead of `create index`.\n\t */\n\tunique?: boolean;\n\n\t/**\n\t * If set, the index will be created as `create index ... using { 'btree' | 'hash' }`.\n\t */\n\tusing?: 'btree' | 'hash';\n\n\t/**\n\t * If set, the index will be created as `create index ... algorythm { 'default' | 'inplace' | 'copy' }`.\n\t */\n\talgorythm?: 'default' | 'inplace' | 'copy';\n\n\t/**\n\t * If set, adds locks to the index creation.\n\t */\n\tlock?: 'default' | 'none' | 'shared' | 'exclusive';\n}\n\nexport type IndexColumn = SingleStoreColumn | SQL;\n\nexport class IndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilderOn';\n\n\tconstructor(private name: string, private unique: boolean) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder {\n\t\treturn new IndexBuilder(this.name, columns, this.unique);\n\t}\n}\n\nexport interface AnyIndexBuilder {\n\tbuild(table: SingleStoreTable): Index;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IndexBuilder extends AnyIndexBuilder {}\n\nexport class IndexBuilder implements AnyIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilder';\n\n\t/** @internal */\n\tconfig: IndexConfig;\n\n\tconstructor(name: string, columns: IndexColumn[], unique: boolean) {\n\t\tthis.config = {\n\t\t\tname,\n\t\t\tcolumns,\n\t\t\tunique,\n\t\t};\n\t}\n\n\tusing(using: IndexConfig['using']): this {\n\t\tthis.config.using = using;\n\t\treturn this;\n\t}\n\n\talgorythm(algorythm: IndexConfig['algorythm']): this {\n\t\tthis.config.algorythm = algorythm;\n\t\treturn this;\n\t}\n\n\tlock(lock: IndexConfig['lock']): this {\n\t\tthis.config.lock = lock;\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tbuild(table: SingleStoreTable): Index {\n\t\treturn new Index(this.config, table);\n\t}\n}\n\nexport class Index {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndex';\n\n\treadonly config: IndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: IndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport type GetColumnsTableName<TColumns> = TColumns extends\n\tAnySingleStoreColumn<{ tableName: infer TTableName extends string }> | AnySingleStoreColumn<\n\t\t{ tableName: infer TTableName extends string }\n\t>[] ? TTableName\n\t: never;\n\nexport function index(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, false);\n}\n\nexport function uniqueIndex(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, true);\n}\n\n/* export interface AnyFullTextIndexBuilder {\n\tbuild(table: SingleStoreTable): FullTextIndex;\n} */\n/*\ninterface FullTextIndexConfig {\n\tversion?: number;\n}\n\ninterface FullTextIndexFullConfig extends FullTextIndexConfig {\n\tcolumns: IndexColumn[];\n\n\tname: string;\n}\n\nexport class FullTextIndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilderOn';\n\n\tconstructor(private name: string, private config: FullTextIndexConfig) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): FullTextIndexBuilder {\n\t\treturn new FullTextIndexBuilder({\n\t\t\tname: this.name,\n\t\t\tcolumns: columns,\n\t\t\t...this.config,\n\t\t});\n\t}\n} */\n\n/*\nexport interface FullTextIndexBuilder extends AnyFullTextIndexBuilder {}\n\nexport class FullTextIndexBuilder implements AnyFullTextIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilder'; */\n\n/** @internal */\n/* config: FullTextIndexFullConfig;\n\n\tconstructor(config: FullTextIndexFullConfig) {\n\t\tthis.config = config;\n\t} */\n\n/** @internal */\n/* build(table: SingleStoreTable): FullTextIndex {\n\t\treturn new FullTextIndex(this.config, table);\n\t}\n}\n\nexport class FullTextIndex {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndex';\n\n\treadonly config: FullTextIndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: FullTextIndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport function fulltext(name: string, config: FullTextIndexConfig): FullTextIndexBuilderOn {\n\treturn new FullTextIndexBuilderOn(name, config);\n}\n\nexport type SortKeyColumn = SingleStoreColumn | SQL;\n\nexport class SortKeyBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKeyBuilder';\n\n\tconstructor(private columns: SortKeyColumn[]) {} */\n\n/** @internal */\n/* build(table: SingleStoreTable): SortKey {\n\t\treturn new SortKey(this.columns, table);\n\t}\n}\n\nexport class SortKey {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKey';\n\n\tconstructor(public columns: SortKeyColumn[], public table: SingleStoreTable) {}\n}\n\nexport function sortKey(...columns: SortKeyColumn[]): SortKeyBuilder {\n\treturn new SortKeyBuilder(columns);\n}\n */\n"],"mappings":"AAAA,SAAS,kBAAkB;AAiCpB,MAAM,eAAe;AAAA,EAG3B,YAAoB,MAAsB,QAAiB;AAAvC;AAAsB;AAAA,EAAkB;AAAA,EAF5D,QAAiB,UAAU,IAAY;AAAA,EAIvC,MAAM,SAAwD;AAC7D,WAAO,IAAI,aAAa,KAAK,MAAM,SAAS,KAAK,MAAM;AAAA,EACxD;AACD;AASO,MAAM,aAAwC;AAAA,EACpD,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC;AAAA,EAEA,YAAY,MAAc,SAAwB,QAAiB;AAClE,SAAK,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,OAAmC;AACxC,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAEA,UAAU,WAA2C;AACpD,SAAK,OAAO,YAAY;AACxB,WAAO;AAAA,EACR;AAAA,EAEA,KAAK,MAAiC;AACrC,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,OAAgC;AACrC,WAAO,IAAI,MAAM,KAAK,QAAQ,KAAK;AAAA,EACpC;AACD;AAEO,MAAM,MAAM;AAAA,EAClB,QAAiB,UAAU,IAAY;AAAA,EAE9B;AAAA,EAET,YAAY,QAAqB,OAAyB;AACzD,SAAK,SAAS,EAAE,GAAG,QAAQ,MAAM;AAAA,EAClC;AACD;AAQO,SAAS,MAAM,MAA8B;AACnD,SAAO,IAAI,eAAe,MAAM,KAAK;AACtC;AAEO,SAAS,YAAY,MAA8B;AACzD,SAAO,IAAI,eAAe,MAAM,IAAI;AACrC;","names":[]}
1
+ {"version":3,"sources":["../../src/singlestore-core/indexes.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { SQL } from '~/sql/sql.ts';\nimport type { AnySingleStoreColumn, SingleStoreColumn } from './columns/index.ts';\nimport type { SingleStoreTable } from './table.ts';\n\ninterface IndexConfig {\n\tname: string;\n\n\tcolumns: IndexColumn[];\n\n\t/**\n\t * If true, the index will be created as `create unique index` instead of `create index`.\n\t */\n\tunique?: boolean;\n\n\t/**\n\t * If set, the index will be created as `create index ... using { 'btree' | 'hash' }`.\n\t */\n\tusing?: 'btree' | 'hash';\n\n\t/**\n\t * If set, the index will be created as `create index ... algorithm { 'default' | 'inplace' | 'copy' }`.\n\t */\n\talgorithm?: 'default' | 'inplace' | 'copy';\n\n\t/**\n\t * If set, adds locks to the index creation.\n\t */\n\tlock?: 'default' | 'none' | 'shared' | 'exclusive';\n}\n\nexport type IndexColumn = SingleStoreColumn | SQL;\n\nexport class IndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilderOn';\n\n\tconstructor(private name: string, private unique: boolean) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): IndexBuilder {\n\t\treturn new IndexBuilder(this.name, columns, this.unique);\n\t}\n}\n\nexport interface AnyIndexBuilder {\n\tbuild(table: SingleStoreTable): Index;\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-interface\nexport interface IndexBuilder extends AnyIndexBuilder {}\n\nexport class IndexBuilder implements AnyIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndexBuilder';\n\n\t/** @internal */\n\tconfig: IndexConfig;\n\n\tconstructor(name: string, columns: IndexColumn[], unique: boolean) {\n\t\tthis.config = {\n\t\t\tname,\n\t\t\tcolumns,\n\t\t\tunique,\n\t\t};\n\t}\n\n\tusing(using: IndexConfig['using']): this {\n\t\tthis.config.using = using;\n\t\treturn this;\n\t}\n\n\talgorithm(algorithm: IndexConfig['algorithm']): this {\n\t\tthis.config.algorithm = algorithm;\n\t\treturn this;\n\t}\n\n\tlock(lock: IndexConfig['lock']): this {\n\t\tthis.config.lock = lock;\n\t\treturn this;\n\t}\n\n\t/** @internal */\n\tbuild(table: SingleStoreTable): Index {\n\t\treturn new Index(this.config, table);\n\t}\n}\n\nexport class Index {\n\tstatic readonly [entityKind]: string = 'SingleStoreIndex';\n\n\treadonly config: IndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: IndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport type GetColumnsTableName<TColumns> = TColumns extends\n\tAnySingleStoreColumn<{ tableName: infer TTableName extends string }> | AnySingleStoreColumn<\n\t\t{ tableName: infer TTableName extends string }\n\t>[] ? TTableName\n\t: never;\n\nexport function index(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, false);\n}\n\nexport function uniqueIndex(name: string): IndexBuilderOn {\n\treturn new IndexBuilderOn(name, true);\n}\n\n/* export interface AnyFullTextIndexBuilder {\n\tbuild(table: SingleStoreTable): FullTextIndex;\n} */\n/*\ninterface FullTextIndexConfig {\n\tversion?: number;\n}\n\ninterface FullTextIndexFullConfig extends FullTextIndexConfig {\n\tcolumns: IndexColumn[];\n\n\tname: string;\n}\n\nexport class FullTextIndexBuilderOn {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilderOn';\n\n\tconstructor(private name: string, private config: FullTextIndexConfig) {}\n\n\ton(...columns: [IndexColumn, ...IndexColumn[]]): FullTextIndexBuilder {\n\t\treturn new FullTextIndexBuilder({\n\t\t\tname: this.name,\n\t\t\tcolumns: columns,\n\t\t\t...this.config,\n\t\t});\n\t}\n} */\n\n/*\nexport interface FullTextIndexBuilder extends AnyFullTextIndexBuilder {}\n\nexport class FullTextIndexBuilder implements AnyFullTextIndexBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndexBuilder'; */\n\n/** @internal */\n/* config: FullTextIndexFullConfig;\n\n\tconstructor(config: FullTextIndexFullConfig) {\n\t\tthis.config = config;\n\t} */\n\n/** @internal */\n/* build(table: SingleStoreTable): FullTextIndex {\n\t\treturn new FullTextIndex(this.config, table);\n\t}\n}\n\nexport class FullTextIndex {\n\tstatic readonly [entityKind]: string = 'SingleStoreFullTextIndex';\n\n\treadonly config: FullTextIndexConfig & { table: SingleStoreTable };\n\n\tconstructor(config: FullTextIndexConfig, table: SingleStoreTable) {\n\t\tthis.config = { ...config, table };\n\t}\n}\n\nexport function fulltext(name: string, config: FullTextIndexConfig): FullTextIndexBuilderOn {\n\treturn new FullTextIndexBuilderOn(name, config);\n}\n\nexport type SortKeyColumn = SingleStoreColumn | SQL;\n\nexport class SortKeyBuilder {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKeyBuilder';\n\n\tconstructor(private columns: SortKeyColumn[]) {} */\n\n/** @internal */\n/* build(table: SingleStoreTable): SortKey {\n\t\treturn new SortKey(this.columns, table);\n\t}\n}\n\nexport class SortKey {\n\tstatic readonly [entityKind]: string = 'SingleStoreSortKey';\n\n\tconstructor(public columns: SortKeyColumn[], public table: SingleStoreTable) {}\n}\n\nexport function sortKey(...columns: SortKeyColumn[]): SortKeyBuilder {\n\treturn new SortKeyBuilder(columns);\n}\n */\n"],"mappings":"AAAA,SAAS,kBAAkB;AAiCpB,MAAM,eAAe;AAAA,EAG3B,YAAoB,MAAsB,QAAiB;AAAvC;AAAsB;AAAA,EAAkB;AAAA,EAF5D,QAAiB,UAAU,IAAY;AAAA,EAIvC,MAAM,SAAwD;AAC7D,WAAO,IAAI,aAAa,KAAK,MAAM,SAAS,KAAK,MAAM;AAAA,EACxD;AACD;AASO,MAAM,aAAwC;AAAA,EACpD,QAAiB,UAAU,IAAY;AAAA;AAAA,EAGvC;AAAA,EAEA,YAAY,MAAc,SAAwB,QAAiB;AAClE,SAAK,SAAS;AAAA,MACb;AAAA,MACA;AAAA,MACA;AAAA,IACD;AAAA,EACD;AAAA,EAEA,MAAM,OAAmC;AACxC,SAAK,OAAO,QAAQ;AACpB,WAAO;AAAA,EACR;AAAA,EAEA,UAAU,WAA2C;AACpD,SAAK,OAAO,YAAY;AACxB,WAAO;AAAA,EACR;AAAA,EAEA,KAAK,MAAiC;AACrC,SAAK,OAAO,OAAO;AACnB,WAAO;AAAA,EACR;AAAA;AAAA,EAGA,MAAM,OAAgC;AACrC,WAAO,IAAI,MAAM,KAAK,QAAQ,KAAK;AAAA,EACpC;AACD;AAEO,MAAM,MAAM;AAAA,EAClB,QAAiB,UAAU,IAAY;AAAA,EAE9B;AAAA,EAET,YAAY,QAAqB,OAAyB;AACzD,SAAK,SAAS,EAAE,GAAG,QAAQ,MAAM;AAAA,EAClC;AACD;AAQO,SAAS,MAAM,MAA8B;AACnD,SAAO,IAAI,eAAe,MAAM,KAAK;AACtC;AAEO,SAAS,YAAY,MAA8B;AACzD,SAAO,IAAI,eAAe,MAAM,IAAI;AACrC;","names":[]}