Lianja Cloud Server supports OData-compatible data access. The Server handles ODBC connections as well as HTTP requests using OData URIs. In this article I will show you how to use Lianja Cloud Server with OData URIs that will allow you to perform CRUD (Create, Read, Update and Delete) operations on your data. Making OData requests from jquery and/or the Lianja HTML5 Client in a Web App is extremely straightforward and simple. Unlike other OData implementations, Lianja Cloud Server OData services does not require any server-side configuration of web services. So let's get started and see what we can do with this new OData functionality. When testing your OData queries I find it useful to be able to just type the URIs in the address bar of Google Chrome. Any JSON data returned from the OData request is displayed in the browser tab (unlike IE which prompts you to save the JSON file into downloads). First thing we need to do is make sure that we have enabled HTTP services and OData Read Services through the Lianja Server Manager which you will find in the Control Panel on Windows. 1/5
Now fire up Chrome on your desktop and type the following into the address bar. http://127.0.0.1/odata/southwind/customers You should now see JSON format output in the browser window showing all the "customer" records from the "southwind" database. Now let's just select the top 5 records and also only request the customerid and contactname 2/5
columns using the $top and $select arguments. We can filter what data is returned using the $filter argument. Note that in OData all arguments begin with a $ and are concatenated together using & just like a normal web page URI. Notice that when we specify conditions e.g. for the $filter in this case we must specify these in OData-style: 3/5
= =!= and or + * / % - eq ge ne and or add mul div mod sub The Lianja SQL Server will generate SQL behind the scenes and optimize the query based on what indexes exist on the specified table. We can speed things up by specifying a "value selector" on the table. /odata/southwind/customers('a') The OData server will use heuristics to determine the column that 'A' is referring to in the 'customers' table. If the column customersid exists it wll be used, if that does not exist and the table is a 'collection' i.e. ends with a 's', the 's' will be removed and the column customerid will be looked up. In many cases this will just work but there are occasions where for example you may want to select all customers where the 'contactname' starts with 'A'. This is accomplished in the following manner. /odata/southwind/customers('a', contactname) There are a range of arguments that can be postfixed onto the URI like this. /odata/southwind/customers('a')?$skip=10&$top=5 The following arguments are available. $top $skip $filter $select $rowid $count Selects the specified number $top=10 of records Skips a number of selected $skip=50 records Selects only those records$filter=contactname that match the specified eq 'A'filter and amount gt 0 Selects only the specified$select=customerid,contactname columns (or expressions) Add the unique rowid into$rowid the output ( rowid ) which can be used to updat Don't return any data just $count tell me how many records would have been select 4/5
$metadata $format $format=jsongrid $format=jsonarray $format=ado $format=excel $format=attachment $format=html $format=csv $format=img $orderby $callback $sql $nocount Returns metadata describing $metadata the columns in the table; name, type, width an The output format $format=json Specify a column or expression $orderby=contactname that the data should be ordered by Specify a callback function $callback=your_javascript_function that will wrap the data returned. This is used with Evaluate a SQL SELECT $sql=select statement directly * from and customers return the results. Note that Don't return the count member $nocount which details the total number of rows that To query for the metadata for a table use the $metadata argument. 5/5