Skip to content

Instantly share code, notes, and snippets.

@avital
Forked from swannodette/SSCollectionJSON.js
Created January 23, 2009 21:06
Show Gist options
  • Save avital/51198 to your computer and use it in GitHub Desktop.
Save avital/51198 to your computer and use it in GitHub Desktop.
read
----
{
"action": "read",
"table": "user/shift/trail/comment",
"constraints": {
"user_id": 67 || [option1, option2, option3] || {range: [range-begin, range-end]}
// if range-begin is null, this means all less than range-add.
// if range-add is null, this means all greater than range-begin.
// "NOW()" works for dates.
},
"properties": "*" || ["username", "summary", "modified"],
"orderby": ["<" || ">", "modified"],
"startIndex": 2,
"range": {
"startIndex": 2, // array base is 0
"count": 20
}
}
- returns array of results
delete
------
{
"action": "delete",
"table": "user/shift/trail/comment",
"constraints": {
"user_id": 67
},
}
- returns number of rows deleted
update
------
{
"action": "update",
"table": "user/shift/trail/comment",
"constraints": {
"user_id": 67
},
"values": {
"user_id": 68,
"name": "Avital"
}
}
- returns number of rows updated
create
------
{
"action": "create",
"table": "user/shift/trail/comment",
"values": {
"name": "Avital"
}
}
- returns new id
bulk operations
++++++++++++++
just pass an array of those json's
the result will be an array of the results of each operation with respective indices
OH MY GOT HOW CRAZY IS THIS
###########################
[
{
"action": "read",
"table": "workset",
"properties": "*",
"constraints": {
"userid": 1
}
},
{
"action": "read",
"table": "worksinset",
"properties": "COUNT(*)",
"constraints": {
"setid": "%id%"
}
}
]
- "COUNT(*)" in the properties is just a simple way to get the count by (ab)using SQL syntax
- "%id%" in constraints means (CHECK THIS OUT): go over all the values for column "id" from the previous action in the bulk operation and substitute each one and then run it and put it all in an array. WOW HOW CRAZY
stream/collectiond bridge
+++++++++++++++++++++++++
Any stream can be acted upon by using pseudo-table !<stream-id>, for example "!3"
superstreams
++++++++++++
A stream that has "superstream"=1 means it is an aggregation of several other streams. Any event posted on that stream will use its object_ref to directly refer to another stream id. If that other stream is also a superstream, it will recursively read them all.
If you want to view which streams are part of a superstream rather than viewing the whole expanded aggregation, set "bare": 1 in the json description for your object, like
{
"action": "read",
"table": "!2",
"properties": "*",
"bare": 1
}
crazy url retrieval
+++++++++++++++++++
Any table that has a url column (right now just events have this), if you set anything in the url column, when reading that table it will automatically retrieve the contents of that url and return them as if there is a column called url_reponse. It's like magic but wayyyyy insecure so we should later on restrict it only to certain URLs or something.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment