Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Right the SQL expression is validating that you're referencing tables that are included in the query and that all column references exist, not that the parameter value matches the property type, although SQLite and MySQL does allow you to use a string to query an int column, e.g:

    SELECT * from Contact where id = '1'
With that said you can achieve something similar in litdb with a custom expression:

    const eq = <T,V>(ref:(x:T)=>V, value:V) => (x:T) => $`${ref(x)} = ${value}`
Which will type check that the value matches the column type:

    .where(eq(c => c.id, 2))
and fail type check when they don't:

    .where(eq(c => c.id, '2'))
Examples of other custom expressions: https://litdb.dev/#composable


Understood. IMHO it would be desirable to have built in support for all common crud operations to be end-to-end type-safe.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: