3 ms·
My first reaction to seeing an SQL-based API is 'ugh'. SQL is complex and a little cumbersome, and easy to get wrong. My second reaction is 'oh, thank god'. I'
by danudey 9y ago
My first reaction to seeing an SQL-based API is 'ugh'. SQL is complex and a little cumbersome, and easy to get wrong.
My second reaction is 'oh, thank god'. I'm so tired of having APIs where I have to go through the 'get the list of users', 'iterate over the list to create a map', 'get the list of messages', 'iterate over the list of messages and add the username to the data structure', 'oh wait I have to get the channel list separately too, seriously?', 'get the list of channels', 'iterate over the list to create a map', etc.
I love Slack's API, for example, but having to fetch a list of users, along with the entirety of their profile data and everything about them, then do the same for channels, then do the same for messages, then tie everything together, it's very cumbersome compared to
SELECT m.message, m.when, u.username, u.name, c.name FROM messages m LEFT JOIN users u ON (m.uid == u.uid) LEFT JOIN (m.cid == c.cid) where c.name == "#general" LIMIT 50;
(or whatever it should be, I haven't done SQL in ages)
And I also get a lot fewer records, especially when I'm trying to get the last 50 messages from #general on a Slack instance that has 400 users and 200 channels.
- objclxt 9y agoThat's one of the problems that GraphQL is intended to solve, specifically you don't want to write your API queries directly in SQL but you also want the flexibility to chain queries together and specify the exact types of data you require.
- nikki93 9y agoWonder what you'd think of a pull + datalog mix, which is what Datomic / Datascript do: https://github.com/Datomic/day-of-datomic/blob/master/tutorial/pull.clj#L102-L115 https://github.com/Datomic/day-of-datomic/blob/master/tutori... The neat thing about the syntax there is that it's a datastructure which if you write a generic visual editor like https://developers.google.com/blockly/ https://developers.google.com/blockly/ over that only fits puzzle pieces when they satisfy https://clojure.org/about/spec https://clojure.org/about/spec you could...
- bm1362 9y agoFor an internal hackathon we basically tried to do this but ran out of time. We built our own query driven API layer that is basically a shim over datomics query and pull apis.