Comparing version 1.0.1 to 1.0.2
@@ -16,3 +16,3 @@ import { type BaseSchema, Table as BaseTable, type TableOptions } from './table'; | ||
*/ | ||
export type QueryInfer<T extends string> = T extends `${infer _} $${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 _}$${infer Prop} ${infer Rest}` ? PropObject<Prop> & QueryInfer<Rest> : T extends `${infer _}$${infer Prop}` ? PropObject<Prop> : T extends `$${infer Prop}` ? PropObject<Prop> : {}; | ||
/** | ||
@@ -29,5 +29,7 @@ * Table type | ||
*/ | ||
export function query<Q extends string>(query: Q): Q & QueryInfer<Q>; | ||
export function query<Q extends string>(query: Q): Q & { | ||
infer: QueryInfer<Q>; | ||
}; | ||
export {}; | ||
} | ||
export default sql; |
// @bun | ||
class j extends Function{O;init;constructor(O){super();this.options=O;const{name:$,schema:N,primaryKeys:u,foreignKeys:v,withoutRowID:x}=this.options,f=[];for(let S in N)f.push(`${S} ${N[S]}`);if(Array.isArray(u))f.push(`PRIMARY KEY(${u.join(",")})`);if(Array.isArray(v))for(let S of v)f.push(`FOREIGN KEY(${S.keys.join(",")}) REFERENCES ${S.ref}`);this.init=`CREATE TABLE IF NOT EXISTS ${$} (${f.join(",")})${x===!0?" WITHOUT ROWID":""}`}col(...O){return O}toString=()=>this.options.name}var z={apply:(O,$,N)=>`${O.options.name}(${N.join(",")})`,get:(O,$)=>{if($ in O)return Reflect.get(O,$);if(typeof $==="string"&&$.startsWith("$"))return O[$]=`${O.options.name}.${$.substring(1)}`;return null}},m;(function(E){function O(N){return new Proxy(new j(N),z)}E.table=O;function $(N){return N}E.query=$})(m||(m={}));var G=m;export{G as default}; | ||
class $ extends Function{O;init;constructor(O){super();this.options=O;const{name:N,schema:j,primaryKeys:f,foreignKeys:m,withoutRowID:n}=this.options,S=[];for(let x in j)S.push(`${x} ${j[x]}`);if(Array.isArray(f))S.push(`PRIMARY KEY(${f.join(",")})`);if(Array.isArray(m))for(let x of m)S.push(`FOREIGN KEY(${x.keys.join(",")}) REFERENCES ${x.ref}`);this.init=`CREATE TABLE IF NOT EXISTS ${N} (${S.join(",")})${n===!0?" WITHOUT ROWID":""}`}col(...O){return O}toString=()=>this.options.name}var v={apply:(O,N,j)=>`${O.options.name}(${j.join(",")})`,get:(O,N)=>{if(N in O)return Reflect.get(O,N);if(typeof N==="string"&&N.startsWith("$"))return O[N]=`${O.options.name}.${N.substring(1)}`;return null}},d;(function(C){function O(j){return new Proxy(new $(j),v)}C.table=O;function N(j){return j}C.query=N})(d||(d={}));var F=d;export{F as default}; |
{ | ||
"name": "sql-light", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"module": "lib/index.ts", | ||
@@ -5,0 +5,0 @@ "types": "lib/index.d.ts", |
@@ -27,3 +27,3 @@ # `sql-light` | ||
// Feed to Bun query initializer | ||
const query = db.query<{ pass: string }, typeof selectUser>(selectUser); | ||
const query = db.query<{ pass: string }, typeof selectUser.infer>(selectUser); | ||
``` |
4090
67