Comparing version 1.0.4 to 1.0.5
@@ -0,4 +1,5 @@ | ||
/// <reference types="node" /> | ||
import { type BaseSchema, Table as BaseTable, type TableOptions } from './table'; | ||
export type TableExtension<Name extends string, Schema extends BaseSchema> = { | ||
[K in `$${Extract<keyof Schema, string>}`]: `${Name}.${K}`; | ||
[K in Extract<keyof Schema, string> as `$${K}`]: `${Name}.${K}`; | ||
} & { | ||
@@ -11,10 +12,14 @@ [K in Extract<keyof Schema, string> as `:${K}`]: K; | ||
*/ | ||
export type Value = string | number | boolean; | ||
export type Value = string | number | null | Buffer; | ||
type EndToken = ',' | ' ' | ';' | ')'; | ||
type Analyze<T extends string, Current extends string = ''> = T extends `${infer Char}${infer Rest}` ? CharCheck<Char, Current, Rest> : T extends EndToken ? {} : PropObject<`${Current}${T}`>; | ||
type CharCheck<Char extends string, Current extends string, Rest extends string = ''> = Char extends EndToken ? PropObject<Current> & QueryInfer<Rest> : Analyze<Rest, `${Current}${Char}`>; | ||
type PropObject<Name extends string> = { | ||
[K in `$${Name}`]: Value; | ||
}; | ||
type SliceEnd<T extends string, Token extends string> = T extends `${string}${Token}${infer Rest}` ? Rest : ''; | ||
/** | ||
* Infer from a query string | ||
*/ | ||
export type QueryInfer<T extends string> = T extends `${string}$${infer Prop},${infer Rest}` ? PropObject<Prop> & QueryInfer<Rest> : T extends `${string}$${infer Prop})${infer Rest}` ? PropObject<Prop> & QueryInfer<Rest> : T extends `${string}$${infer Prop}=${infer Rest}` ? PropObject<Prop> & QueryInfer<Rest> : T extends `${string}$${infer Prop} ${infer Rest}` ? PropObject<Prop> & QueryInfer<Rest> : T extends `${infer _}$${infer Prop}` ? PropObject<Prop> : T extends `$${infer Prop}` ? PropObject<Prop> : {}; | ||
export type QueryInfer<T extends string> = T extends `${infer X}'${infer Y}` ? QueryInfer<X> & QueryInfer<SliceEnd<Y, `'`>> : T extends `${infer X}"${infer Y}` ? QueryInfer<X> & QueryInfer<SliceEnd<Y, `"`>> : T extends `${string}$${infer Rest}` ? Analyze<Rest> : {}; | ||
/** | ||
@@ -33,2 +38,3 @@ * Table type | ||
infer: QueryInfer<Q>; | ||
value: Q; | ||
}; | ||
@@ -35,0 +41,0 @@ export {}; |
// @bun | ||
class U extends Function{E;init;cols;constructor(E){super();this.options=E;const{name:d,schema:j,primaryKeys:f,foreignKeys:m,withoutRowID:v}=this.options,S=[];for(let P in j)S.push(`${P} ${j[P]}`);if(Array.isArray(f))S.push(`PRIMARY KEY(${f.join(",")})`);if(Array.isArray(m))for(let P of m)S.push(`FOREIGN KEY(${P.keys.join(",")}) REFERENCES ${P.ref}`);this.init=`CREATE TABLE IF NOT EXISTS ${d} (${S.join(",")})${v===!0?" WITHOUT ROWID":""}`;const u=[];for(let P in j)u.push(P);this.cols=u}toString=()=>this.options.name}var x={apply:(E,d,j)=>`${E.options.name}(${j.join(",")})`,get:(E,d)=>{if(d in E)return Reflect.get(E,d);if(typeof d==="string"){switch(d[0]){case"$":Reflect.set(E,d,`${E.options.name}.${d.substring(1)}`);break;case":":Reflect.set(E,d,d.substring(1));break}return Reflect.get(E,d)}return null}},b;(function(C){function E(j){return new Proxy(new U(j),x)}C.table=E;function d(j){return j}C.query=d})(b||(b={}));var G=b;export{G as default}; | ||
class S extends Function{$;init;cols;constructor($){super();this.options=$;const{name:n,schema:x,primaryKeys:j,foreignKeys:v,withoutRowID:A}=this.options,d=[];for(let E in x)d.push(`${E} ${x[E]}`);if(Array.isArray(j))d.push(`PRIMARY KEY(${j.join(",")})`);if(Array.isArray(v))for(let E of v)d.push(`FOREIGN KEY(${E.keys.join(",")}) REFERENCES ${E.ref}`);this.init=`CREATE TABLE IF NOT EXISTS ${n} (${d.join(",")})${A===!0?" WITHOUT ROWID":""}`;const z=[];for(let E in x)z.push(E);this.cols=z}toString=()=>this.options.name}var C={apply:($,n,x)=>`${$.options.name}(${x.join(",")})`,get:($,n)=>{if(n in $)return Reflect.get($,n);if(typeof n==="string"){switch(n[0]){case"$":Reflect.set($,n,`${$.options.name}.${n.substring(1)}`);break;case":":Reflect.set($,n,n.substring(1));break}return Reflect.get($,n)}return null}},U;(function(I){function $(x){return new Proxy(new S(x),C)}I.table=$;function n(x){return x}I.query=n})(U||(U={}));var L=U;export{L as default}; |
{ | ||
"name": "sql-light", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"module": "lib/index.ts", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
5043
79