trilogy
Version:
TypeScript SQLite layer with support for both native C++ & pure JavaScript drivers.
95 lines (94 loc) • 5.02 kB
TypeScript
import Model from './model';
import * as t from 'runtypes';
import { Raw, SchemaBuilder, QueryBuilder } from 'knex';
export declare type Fn<T extends any[], R = any> = (...args: T) => R;
export declare type Query = Raw | QueryBuilder<any, any> | SchemaBuilder | Promise<any>;
export declare type QueryOptions<D extends ReturnDict = LooseObject> = {
model?: Model<D>;
needResponse?: boolean;
internal?: boolean;
};
export declare type DistinctArrayTuple<T, V = any> = T extends [string, string, V] ? [string, string, V] : T extends [string, V] ? [string, V] : T extends V[] ? V[] : V;
export declare type StringKeys<D = LooseObject> = Extract<keyof D, string>;
export declare type LooseObject = Record<string, any>;
export declare type ValueOf<D> = D[keyof D];
export declare type Defined<T> = {
[P in keyof T]: Exclude<T[P], undefined>;
};
export declare type Criteria2<D = LooseObject> = [StringKeys<D>, D[StringKeys<D>]];
export declare type Criteria3<D = LooseObject> = [StringKeys<D>, string, D[StringKeys<D>]];
export declare type CriteriaObj<D = LooseObject> = Partial<D>;
export declare type CriteriaBase<D = LooseObject> = Criteria2<DistinctArrayTuple<D>> | Criteria3<DistinctArrayTuple<D>> | CriteriaObj<D>;
export declare type CriteriaBaseNormalized<D = LooseObject> = Criteria3<DistinctArrayTuple<D>> | CriteriaObj<D>;
export declare type CriteriaList<D = LooseObject> = CriteriaBase<DistinctArrayTuple<D>>[];
export declare type CriteriaListNormalized<D = LooseObject> = CriteriaBaseNormalized<DistinctArrayTuple<D>>[];
export declare type Criteria<D = LooseObject> = CriteriaBase<D> | CriteriaList<D>;
export declare type CriteriaNormalized<D = LooseObject> = CriteriaBaseNormalized<D> | CriteriaListNormalized<D>;
export declare const Index: t.Union3<t.String, t.Array<t.Union2<t.String, t.Array<t.String, false>>, false>, t.StringDictionary<t.Union2<t.String, t.Array<t.String, false>>>>;
export declare const GroupClause: t.Union2<t.String, t.Array<t.String, false>>;
export declare const OrderClause: t.Union2<t.String, t.Tuple2<t.String, t.String>>;
export declare const TrilogyOptions: t.Part<{
client: t.Union2<t.Literal<"sqlite3">, t.Literal<"sql.js">>;
dir: t.String;
}>;
export declare const ModelOptions: t.Part<{
index: t.Union3<t.String, t.Array<t.Union2<t.String, t.Array<t.String, false>>, false>, t.StringDictionary<t.Union2<t.String, t.Array<t.String, false>>>>;
primary: t.Array<t.String, false>;
unique: t.Array<t.String, false>;
timestamps: t.Boolean;
}>;
export declare const AggregateOptions: t.Part<{
distinct: t.Boolean;
group: t.Union2<t.String, t.Array<t.String, false>>;
order: t.Union2<t.String, t.Tuple2<t.String, t.String>>;
}>;
export declare const CreateOptions: t.Part<{
raw: t.Boolean;
}>;
export declare const FindOptions: t.Part<{
limit: t.Number;
order: t.Union2<t.String, t.Tuple2<t.String, t.String>>;
random: t.Boolean;
raw: t.Boolean;
skip: t.Number;
}>;
export declare const UpdateOptions: t.Part<{
raw: t.Boolean;
}>;
export declare const ColumnKind: t.Constraint<t.Union2<t.String, t.Function>, string | ((...args: any[]) => any), unknown>;
export declare const ColumnDescriptor: t.Part<{
defaultTo: t.Unknown;
index: t.String;
notNullable: t.Boolean;
nullable: t.Boolean;
primary: t.Boolean;
unique: t.Boolean;
type: t.Constraint<t.Union2<t.String, t.Function>, string | ((...args: any[]) => any), unknown>;
get: t.Function;
set: t.Function;
}>;
export declare type Index = t.Static<typeof Index>;
export declare type Order = t.Static<typeof OrderClause>;
export declare type Group = t.Static<typeof GroupClause>;
export declare type TrilogyOptions = t.Static<typeof TrilogyOptions>;
export declare type ModelOptions = t.Static<typeof ModelOptions>;
export declare type AggregateOptions = t.Static<typeof AggregateOptions>;
export declare type CreateOptions = t.Static<typeof CreateOptions>;
export declare type UpdateOptions = t.Static<typeof UpdateOptions>;
export declare type FindOptions = t.Static<typeof FindOptions>;
export declare type ColumnKind = t.Static<typeof ColumnKind>;
export declare type ColumnDescriptor = t.Static<typeof ColumnDescriptor>;
export declare type SchemaRaw<D = LooseObject> = {
[P in keyof Partial<D>]: ColumnKind | ColumnDescriptor;
};
export declare type Schema<D = LooseObject> = {
[P in keyof Partial<D>]: ColumnDescriptor;
};
export declare type SqlJsResponse = Array<{
columns: string[];
values: any[];
}>;
export declare type StorageType = string | number | Date | null | undefined;
export declare type ReturnType = string | number | boolean | null | undefined | any[] | Date | LooseObject;
export declare type ReturnDict = Record<string, ReturnType>;
export declare type CastToDefinition = Record<string, StorageType> | [string, StorageType] | [string, string, StorageType] | CriteriaList | never;