import { DataSet } from './DataSet'; import { DataSource } from './DataSource'; import { PaginationResult } from './PaginationResult'; import { Field, HasAlias, HasDistinct, HasFieldValues, HasGroupByFields, HasHavingConditions, HasJoins, HasLimit, HasOffset, HasSelectFields, HasTable, HasWhen, HasWhereConditions } from './query'; import { HasOrderByFields } from './query/features/HasOrderByFields'; export declare class DataTable { private source; constructor(source: DataSource, name: string); get(): Promise>; first(): Promise; /** * Returns the number of records that match the current query, ignoring any * limit/offset/order-by clause. Honours where conditions, joins, group-by and * having. When a column is given (other than '*') and the query is distinct, * a COUNT(DISTINCT column) is emitted. * * await DB.table('users').where('active', 1).count() // → number * await DB.table('users').distinct().count('country') // COUNT(DISTINCT country) */ count(column?: Field): Promise; /** * SUM of a column over the current query, as a number. An empty result set * sums to 0 — there is no "sum of nothing" worth distinguishing from zero, * and the same choice Eloquent's `sum()` makes. * * await DB.table('orders').where('paid', 1).sum('amount') // → number */ sum(column: Field): Promise; /** * AVG of a column over the current query, or null when nothing matched. * Unlike a sum, an average of no rows is genuinely undefined rather than 0. */ avg(column: Field): Promise; /** * MIN of a column over the current query, or null when nothing matched. * * The value is returned exactly as the driver produced it, with no cast * applied — `MIN` is just as useful over dates and strings as over numbers, * and PostgreSQL and SQLite disagree on how they hand a timestamp back. The * type parameter is a convenience for the caller, not a conversion. */ min(column: Field): Promise; /** MAX of a column over the current query, or null when nothing matched. See `min`. */ max(column: Field): Promise; /** * Length-aware pagination. Runs a COUNT * for the total and a windowed SELECT for the page, then returns both plus * the navigation metadata. * * const page = await DB.table('users').orderBy('name').paginate(15, 2) * // { data, total, perPage, currentPage, lastPage, from, to } */ paginate(perPage?: number, page?: number): Promise>; /** * Inserts a single record or a batch of records. Mirrors Eloquent's * `DB::table('x')->insert($values)`, which accepts either one row or an array * of rows and emits a single `INSERT INTO t (..) VALUES (..), (..)` statement: * * await DB.table('users').insert({ name: 'Ada' }) * await DB.table('users').insert([{ name: 'Ada' }, { name: 'Bob' }]) * * For a batch the inserted columns are the union of the keys across every row; * a row missing a column inserts NULL for it. Returns the number of affected * rows. Generated primary keys are not read back (use save() for that). */ insert(fields?: DataSet): Promise; insert(rows: DataSet[]): Promise; update(fields?: DataSet): Promise; delete(): Promise; /** * Inserts the given rows, updating the conflicting columns when a row already * exists. Mirrors Eloquent's `upsert($values, $uniqueBy, $update)`: * * await DB.table('player_statistics').upsert( * [{ playerId: 7, points: 120, updatedAt: new Date() }], * 'playerId', // unique-by column(s) * ['points', 'updatedAt'] // columns to overwrite on conflict (optional) * ) * * When `update` is omitted, every inserted column that is not part of * `uniqueBy` is updated. The engine-specific SQL (PostgreSQL/SQLite * `ON CONFLICT`, MySQL `ON DUPLICATE KEY UPDATE`) is produced by the source's * query builder. */ upsert(rows: DataSet[], uniqueBy: string | string[], update?: string[]): Promise; /** Renders a Field as the SQL expression an aggregate can wrap. */ private static columnExpression; /** * Runs `() AS aggregate` over the current query, ignoring * any limit/offset/order-by clause but honouring the where conditions, joins, * group-by and having. Returns every row the engine produced, which is one * row unless the query groups. */ private aggregateRows; /** * Scalar aggregate over the current query: the raw value of the first row, or * null when nothing matched. * * A grouped query has no single scalar to report — the engine returns one row * per group — so this takes the first group's value, the same way Eloquent's * aggregates do. Use `select()` with the aggregate and read the rows back * when you want a value per group. */ private aggregate; private createSelectQuery; private createInsertQuery; private createUpdateQuery; private createDeleteQuery; } export interface DataTable extends HasDistinct, HasLimit, HasOffset, HasOrderByFields, HasGroupByFields, HasFieldValues, HasSelectFields, HasTable, HasAlias, HasWhereConditions, HasHavingConditions, HasJoins, HasWhen { }