UNPKG

sqlmongoose

Version:

Mongoose-like schemas and models for SQLite3

30 lines (29 loc) 902 B
type SchemaType = 'String' | 'Number' | 'Boolean' | 'Date' | 'Array' | 'Map' | 'Mixed'; interface SchemaField { type: SchemaType | SchemaField[]; required?: boolean; unique?: boolean; default?: any; of?: SchemaField | SchemaType; validate?: (value: any) => Promise<boolean> | boolean; ref?: string; index?: boolean; } interface SchemaDefinition { [key: string]: SchemaField | SchemaType | SchemaField[]; } export declare class Schema { private definition; private hooks; constructor(definition: SchemaDefinition); private normalizeDefinition; pre(hook: 'save' | 'update', fn: Function): void; post(hook: 'save' | 'update', fn: Function): void; runValidation(data: any): Promise<boolean>; createTable(tableName: string): string[]; private getSqliteType; getRelationships(): { [key: string]: string; }; } export {};