Batchinterfaceno test imports itinterface Batch<R>A batch: rows and the lines that were rejected on the way.
| Member | Type | What it is |
|---|---|---|
rows | readonly R[] | |
rejected | readonly Rejected[] |
Sources of a load (commons data 0054-sql-loads): where the rows come from, as batches of rows of a type. A source is a value: rows in memory, CSV text read with a typed parser for each column, lines of JSON, or a select of another database. A line that cannot be read is not a thrown error but a rejected line, with its number and why, so that a load says what it did not take.
Batchinterfaceno test imports itinterface Batch<R>A batch: rows and the lines that were rejected on the way.
| Member | Type | What it is |
|---|---|---|
rows | readonly R[] | |
rejected | readonly Rejected[] |
boolconstconst bool: CellParser<boolean>true or false (also yes, no, 1, 0, t, f, in any case).
CellParsertypeno test imports ittype CellParser<T> = (cell: string) => Result<T, string>;How one column of a CSV is read: the text of a cell to a value, or why not.
csvRecordsfunctionfunction csvRecords(textIn: string): readonly { readonly line: number; readonly cells: readonly string[]; }[]The cells of CSV text (RFC 4180: quoted cells, doubled quotes, line breaks inside quotes), with the line each record starts on.
fromCsvfunctionfunction fromCsv<R>(csv: string, columns: { readonly [K in keyof R & string]: CellParser<R[K]> | { readonly parse: CellParser<R[K]>; readonly column: string; }; }, name?: string): Source<R>CSV text whose first line names the columns, read into rows of type R: each key of R has the parser of its cell and the name of its column in the file (the key where not given). A line with a cell that does not parse, or the wrong number of cells, is rejected with its line and why; the rest are taken.
fromJsonLinesfunctionfunction fromJsonLines<R>(jsonl: string, read: (value: unknown) => Result<R, string>, name?: string): Source<R>Lines of JSON, one record each, read by a function that checks a value is a row of R; a line that is not JSON or not a row is rejected.
fromQueryconstconst fromQuery: <R>(select: Select<Scope, R>, on: Runner, name?: string) => Source<R>The rows of a select, run on a database: the way to copy between databases.
fromRowsconstconst fromRows: <R>(rows: readonly R[], name?: string) => Source<R>Rows in memory.
oneOfconstconst oneOf: <T extends string>(...codes: readonly T[]) => CellParser<T>One of a closed list of codes.
optionalconstconst optional: <T>(p: CellParser<T>) => CellParser<T | null>A cell that may be empty: empty is null.
Rejectedinterfaceno test imports itinterface RejectedA line that was not taken.
| Member | Type | What it is |
|---|---|---|
at | number | Where it was: the line (CSV, JSON lines) or the row (others), from 1. |
reason | string | |
raw | string | What it was, as text. |
Sourceinterfaceno test imports itinterface Source<R>Where rows come from.
| Member | Type | What it is |
|---|---|---|
name | string | |
batches | (size: number) => AsyncIterable<Batch<R>> | The rows, in batches of at most size. |
timestampconstno test imports itconst timestamp: CellParser<string>An instant as ISO 8601.