Skip to content

Commit

Permalink
Types organization
Browse files Browse the repository at this point in the history
  • Loading branch information
DallasHoff committed Jul 15, 2024
1 parent 25ec749 commit 7d7d88f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,50 @@ import type { Database, Sqlite3Static } from '@sqlite.org/sqlite-wasm';
import type { CompiledQuery } from 'kysely';
import type { RunnableQuery } from 'drizzle-orm/runnable-query';

// SQLite

export type Sqlite3 = Sqlite3Static;
export type Sqlite3Db = Database;
export type Sqlite3Method = 'get' | 'all' | 'run' | 'values';
export type Sqlite3StorageType = 'memory' | 'opfs';

// Queries

export type Statement = {
sql: string;
params: unknown[];
};

export type ReturningStatement<Result = unknown> =
| Statement // default
| CompiledQuery<Result> // kysely
| RunnableQuery<Result[], 'sqlite'>; // drizzle

export type RawResultData = {
rows: unknown[] | unknown[][];
columns: string[];
};

export type WorkerProxy = ProxyHandler<Worker> &
Record<string, (...args: any) => any>;
// Database status

export type ProcessorConfig = {
databasePath?: string;
};

export type DatabaseInfo = {
databasePath?: string;
databaseSizeBytes?: number;
storageType?: Sqlite3StorageType;
persisted?: boolean;
};

// Worker messages

export type Message = InputMessage | OutputMessage;
export type QueryKey = string;
export type OmitQueryKey<T> = T extends Message ? Omit<T, 'queryKey'> : never;
export type WorkerProxy = ProxyHandler<Worker> &
Record<string, (...args: any) => any>;

export type InputMessage =
| QueryMessage
Expand Down Expand Up @@ -120,6 +130,8 @@ export type InfoMessage = {
info: DatabaseInfo;
};

// User functions

export type UserFunction = CallbackUserFunction | ScalarUserFunction;
export type CallbackUserFunction = {
type: 'callback';
Expand Down

0 comments on commit 7d7d88f

Please sign in to comment.