3 ms·
I can't really understand this without seeing the equivalent SQL as I don't understand datalog. Is this SQL query similar to the first datalog query you listed
by 7thaccount 3y ago
I can't really understand this without seeing the equivalent SQL as I don't understand datalog.
Is this SQL query similar to the first datalog query you listed? I apologize for how HN formatted the below and my lack of understanding for how to get around it.
Select u.name, u.email, u.id
From Users u
Join Cookies c on u.name = c.name
- brendanyounger 3y agoAlmost. What I wrote is more like: create view LoggedInUserView as select u.id as id, u.name as name, u.email as email from Users u join Cookies c on c.name = 'login' and u.id = c.payload->>'userId'; where payload is a json blob. (Indent code by 2+ spaces.) Most people wouldn't design their schema in a SQL database like this with a bunch of special-use relations/views, but datalog encourages you to do so since defining a new relation is the only means of abstraction. In effect, you've created an API endpoint similar to /api/auth/users and, what's more, you can use the LoggedInUserView in other rules to define new relations.