Skip to content

Instantly share code, notes, and snippets.

@joevandyk
Created January 1, 2015 18:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joevandyk/6584c8deffe283573bd3 to your computer and use it in GitHub Desktop.
Save joevandyk/6584c8deffe283573bd3 to your computer and use it in GitHub Desktop.
### Create a table that has name and email, and create a view that versions the way to access the table.
tanga_dev=# create table foos (id serial primary key, name text, email text);
tanga_dev=# create view "1".foos as (select * from foos);
### That's all the code, now we can use http to get, read, update, and delete the data.
$ curl -d '{"name": "bob", "email": "bob@tanga.com"}' http://localhost:3000/foos
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"bob@tanga.com"}]
$ curl -d '{"name": "joe", "email": "joe@tanga.com"}' http://localhost:3000/foos
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"bob@tanga.com"},{"id":4,"name":"joe","email":"joe@tanga.com"}]
$ curl -X PATCH -d '{"email": "joe-new@tanga.com"}' http://localhost:3000/foos?id=eq.4
$ curl http://localhost:3000/foos
[{"id":3,"name":"bob","email":"bob@tanga.com"},{"id":4,"name":"joe","email":"joe-new@tanga.com"}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment