Skip to content

Instantly share code, notes, and snippets.

@mikaelhm
Last active January 2, 2016 13:39
Show Gist options
  • Save mikaelhm/8311789 to your computer and use it in GitHub Desktop.
Save mikaelhm/8311789 to your computer and use it in GitHub Desktop.
Database Module Interface

Database Module Interface

find

find(query, return_obj, user_id, callback)
  • query is a js-obejct that contains the contrains on the data requested.
  • return_obj is a js-object specificaion of which data is requested, in respect to "the data schema"
  • user_id is just the users id and is used to query only the data that is within the users righs
  • callback is a javaScript function that will be call when the data is ready.

query

The query is build as "the data schema", such that each can be constrained using the grammar described in the end of the document

example

upload: {
    id: "12314123214142414",
    upload_date: "$lt 123412431421",
    runs: {
            groups: {
                    	results: {
                            name: "/LTE/",
                       }
           	}
    }
}

return_obj

The return_obj is an object that specifies which data is wanted in the response of the request. If a property is set to 1 it means that the property should be in the returned object, likewise if a property is set to 0 it means that it should be left out.

** Note:** You cannot mix 0's and 1's in a single object. This is done as, all non-mentioned proerties will have the negated value as those inclued.

The return_obj must follow the "the data schema".

examples

{
	upload: {
	    id: 1,
	    upload_date: 1,
	    number_of_runs: 1
   	 	runs: {
   	 		id: 1
		}
}    

This will return a lift of uploads where each of them has the id, upload_date, number_of_runs and a list of runs where each of them just have their id.

{
	upload: {
	    upload_date: 0,
	    number_of_runs: 0
   	 	runs: 0
}    

This will return a list of uploads each with an id. Assuming that id, upload_date, number_of_runs, and runs are the only members of upload in the database.

user_id

user_id is used to ensure that the user cannot access data outside its scope.

callback

callback is a javaScript function with signature: function (returned_objects, err) where

  • returned_objects is an array of obejcts found based on the query and populated as per return_obj.
  • err is an error obejct containg a proper error message.

update

update(query, update, user_id, callback)
  • query is a js-obejct that contains the contrains on which data should be updated.
  • update is a js-object that contains the actual updates.
  • user_id is just the users id and is used to ensure that only data that is within the users righs is updated.
  • callback is a javaScript function that will be call when the the udpdate is done.

query

The query is build as "the data schema", such that each can be constrained using the grammar described in the end of the document

example

{
	upload: {
    	id: "12314123214142414",
    	runs: {
	            groups: {
                   		 	results: {
                	        	id: "1112314124412412124",
            	           	}
        	   	}
    	}
	}
}

update

The update parameter is an object folliwn "the data scheme" such that for each mentioned parameter an "update query" is given using the mongoDB syntax.

Example

{
	upload: {
    	runs: {
	    	groups: {
            	results: {
					result_name: "new name"
            	}
        	}
    	}
	}
}

user_id

user_id is used to ensure that the user cannot update] data outside its scope.

callback

callback is a javaScript function with signature: function (err) where

  • err is an error obejct containg a proper error message.

remove

remove(query,user_id,callback)
  • query is a js-obejct that contains the contrains on which data should be updated.
  • user_id is just the users id and is used to ensure that only data that is within the users righs is updated.
  • callback is a javaScript function that will be call when the the udpdate is done.

query

The query is build as "the data schema", such that each can be constrained using the grammar described in the end of the document. Note: All mebers of the queried object will be removed aswell.

example

{
	upload: {
    	id: "12314123214142414",
	}
}

With this query all runs,groups and results of this particular upload will be deleted.

user_id

user_id is used to ensure that the user cannot update] data outside its scope.

callback

callback is a javaScript function with signature: function (err) where

  • err is an error obejct containg a proper error message.

Query grammar

query 	::= clause | regEx

clause	::= part | (clause) boolOp (clause) | $not (clause)

part 	::= compOp num | listOp list | num
boolOp 	::= $or | $and | $nor

compOp  ::= $lt | $lte | $gt | $gte | $ne 
listOp  ::= $in | $nin

regEx   ::= /some regExp string/
num     ::= parseFloat()
list    ::= [some list]


Examples

($gt 14.2) $or ($lte 11.9)

($in:[1,2,4,6]) $nor (($in:[11,13,14,15]) $and ($in[111,113,114]))

/[0-9]+ LTE/

12.4

Query gramma (mongoDB like operators)

regEx   ::= REGEX-STRING
num     ::= some number int,float,double
list    ::= a list of items

listOp  ::= $in | $nin
compOp  ::= $lt | $lte | $gt | $gte | $ne 

litt ::= compOp num | listOp list | regEx

boolOp  ::= $or | $and | $nor


query ::== litt | (query) boolOp (query) | $not (query)

Examples

  • ($gt 4.2) $and ($lt 11.9)
  • $in:[1,2,4,6]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment