hediet / ts-typed-sql

A fully typed sql builder. Not maintained anymore, use it for your inspiration.
https://hediet.github.io/ts-typed-sql/
54 stars 4 forks source link

Move fromItemToOutRow to table instance it self #10

Open phiresky opened 7 years ago

phiresky commented 7 years ago

I want to be able to do

export const tbl = s.table("tbl", { test: tInteger });

type Tbl = typeof tbl.$rowInstance;

// instead of

type Tbl = FromItemToOutRow<typeof tbl>;

(or similar)

hediet commented 7 years ago

$rowInstance would be a useless (i.e. unused) field. What is the advantage of typeof tbl.$rowInstance; over FromItemToOutRow<typeof tbl>?

phiresky commented 7 years ago

Say I have imported from, myTable, db from somewhere and write a function like this:

async function getSomething() {
    return await db.exec(from(myTable).select(myTable.$all));
}

async function doSomething(myTableInstance: typeof myTable.$rowInstance) {
     ...
}

i.e. I have imported the table definition, but not FromItemToOutRow. Now i could just specify the argument type for doSomething using typeof myTable.$rowInstance instead of having to add more imports or declaring that type somewhere else and importing it.