The example below shows how to define tables and describe their references to other tables. From then on, these references can be used in a RQLTag. Re

GitHub - tureluren/refql: A typesafe Node.js and Deno ORM-like library for composing and running SQL queries.

submited by
Style Pass
2023-03-24 09:30:02

The example below shows how to define tables and describe their references to other tables. From then on, these references can be used in a RQLTag. Relationships are created by passing the table name as a string instead of passing a Table object. This is to avoid circular dependency problems. Tables are uniquely identifiable by the combination schema and tableName (<schema>.<tableName>).

RefQL tries to link 2 tables based on logical column names, using snake case. You can always point RefQL in the right direction if this doesn't work for you.

The querier should have the type signature <T>(query: string, values: any[]) => Promise<T[]>. This function is a necessary in-between piece to make RefQL independent from database clients. This allows you to choose your own client. This is also the place where you can debug or transform a query before it goes to the database or when the result is obtained. Example of a querier for mySQL:

If you use a function placeholder inside a SQLTag or RQLTag, the first parameter of that function will be the parameters with which you execute the tag. If you're working on a RQLTag, u can also access the table through the second parameter of the function placeholder. Raw, When, Values and Values2D can also be constructed with this function.

Leave a Comment