agiletiger / ojotas

The database-first ORM
MIT License
7 stars 4 forks source link

investigate: using sql aliases to give hints to ojotas on how do the assemble #3

Open nicoabie opened 10 months ago

nicoabie commented 10 months ago

today ojotas needs a list of identifiers to know how to do the assemble when querying an entity with its relations it also needs a config file, the ojotasrc.json with aliases and relations

another way would be to have sql queries like this one

select
    u.name as 'name',
    p.title as 'posts[].title',
    p.content as 'posts[].content'
from
    users u left join
    posts p on u.id = p.user_id
;

with this we would not need the configuaration file and it will be more flexible like if we want to return a single post we could do

select
    u.name as 'name',
    p.title as 'lastPost.title',
    p.content as 'lastPost.content'
from
    users u left join
    posts p on u.id = p.user_id
where
    u.id = 1
order by p.createdAt desc
limit 1
;

instrad of having an array with just one post we could directy have an object lastPost.

I believe both ways could co exist depending on user preference on how to work

nicoabie commented 10 months ago

this is the opposite of a JsonPath

I think we could implement this as a separate library possibly called PathJson that exports a function with the following signature

(descriptors: string[], values: unknown[][]) => Record<string, unknown>

shizus commented 7 months ago

The library should be called PattinJson