{"version":3,"file":"count.cjs","names":["SQL","entityKind"],"sources":["../../../src/sqlite-core/query-builders/count.ts"],"sourcesContent":["import { entityKind } from '~/entity.ts';\nimport type { Query } from '~/sql/sql.ts';\nimport { SQL, sql, type SQLWrapper } from '~/sql/sql.ts';\nimport type { SQLiteDialect } from '../dialect.ts';\nimport type { SQLiteSession } from '../session.ts';\nimport type { SQLiteTable } from '../table.ts';\nimport type { SQLiteViewBase } from '../view-base.ts';\n\nexport class SQLiteCountBuilder extends SQL<number> implements SQLWrapper<number> {\n\tstatic override readonly [entityKind]: string = 'SQLiteCountBuilder';\n\n\tprotected dialect: SQLiteDialect;\n\tprotected session: SQLiteSession<any, any>;\n\n\tprivate static buildCount(\n\t\tsource: SQLiteTable | SQLiteViewBase | SQL | SQLWrapper,\n\t\tfilters?: SQL<unknown>,\n\t\tparens?: boolean,\n\t): SQL<number> {\n\t\tconst where = sql` where ${filters}`.if(filters);\n\t\tconst query = sql<number>`select count(*) from ${source}${where}`;\n\n\t\treturn parens ? sql`(${query})` : query;\n\t}\n\n\tconstructor(\n\t\tprotected countConfig: {\n\t\t\tsource: SQLiteTable | SQLiteViewBase | SQL | SQLWrapper;\n\t\t\tfilters?: SQL<unknown>;\n\t\t\tdialect: SQLiteDialect;\n\t\t\tsession: SQLiteSession<any, any>;\n\t\t},\n\t) {\n\t\tsuper(SQLiteCountBuilder.buildCount(countConfig.source, countConfig.filters, true).queryChunks);\n\t\tthis.dialect = countConfig.dialect;\n\t\tthis.session = countConfig.session;\n\t\tthis.mapWith((e) => {\n\t\t\tif (typeof e === 'number') return e;\n\n\t\t\treturn Number(e ?? 0);\n\t\t});\n\t}\n\n\tprivate executableSql: SQL<number> | undefined;\n\tprotected build(): Query {\n\t\tif (!this.executableSql) {\n\t\t\tconst { source, filters } = this.countConfig;\n\t\t\tthis.executableSql = SQLiteCountBuilder.buildCount(source, filters);\n\t\t}\n\n\t\treturn this.dialect.sqlToQuery(this.executableSql);\n\t}\n}\n"],"mappings":";;;;;;AAQA,IAAa,qBAAb,MAAa,2BAA2BA,iBAA0C;CACjF,QAA0BC,0BAAsB;CAEhD,AAAU;CACV,AAAU;CAEV,OAAe,WACd,QACA,SACA,QACc;EAEd,MAAM,QAAQ,gBAAW,wBAAwB,SADnC,gBAAG,UAAU,UAAU,GAAG,QAAQ;AAGhD,SAAO,SAAS,gBAAG,IAAI,MAAM,KAAK;;CAGnC,YACC,AAAU,aAMT;AACD,QAAM,mBAAmB,WAAW,YAAY,QAAQ,YAAY,SAAS,KAAK,CAAC,YAAY;EAPrF;AAQV,OAAK,UAAU,YAAY;AAC3B,OAAK,UAAU,YAAY;AAC3B,OAAK,SAAS,MAAM;AACnB,OAAI,OAAO,MAAM,SAAU,QAAO;AAElC,UAAO,OAAO,KAAK,EAAE;IACpB;;CAGH,AAAQ;CACR,AAAU,QAAe;AACxB,MAAI,CAAC,KAAK,eAAe;GACxB,MAAM,EAAE,QAAQ,YAAY,KAAK;AACjC,QAAK,gBAAgB,mBAAmB,WAAW,QAAQ,QAAQ;;AAGpE,SAAO,KAAK,QAAQ,WAAW,KAAK,cAAc"}