Child pages
  • Create Query components
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

No SQL query components

Apstrata developers can persist their data inside NoSQL key/value pair structures called documents, which are saved into their application store. To retrieve the data that you have persisted in your documents, you can define sophisticated queries to search for document matching your criteria, using the Query API.
While you can invoke the Query API from your client side and pass it all the required parameters to execute your query, you will most of the time need to reuse this same logic across clients or event across server-side components. Since Apstrata always has modularity and reusability in mind, it allows you to encapsulate your query logic into components, called "Saved Queries" using the SaveQuery API

Example 1: load my saved game

You are developing this cool game that runs on mobile devices. Although your game is addictive, your players will stop playing from time to time so you decided to persist the games as Apstrata documents. When your players get back to the game, you need to load its data back to the device, i.e. get the corresponding document using its document key (in our example, we assume our document has the following key 40255DC009EAD2E0966B2CV38728AE4B). 

The simplest way for you to create a "Saved Query" is to log in to the Apstrata workbench, click on "Manage App > Saved Queries > New". This opens a query editor within which a predefined template is already loaded. 

<query>
	<executeACL>creator</executeACL> <!-- This query only authorizes the retrieval of a document created by the caller of the query -->
	<store>cabstore</store> <!-- Put the name of your store here. "DefaultStore" is the default value -->
	<condition><![CDATA[ apsdb.documentKey<string> = {docKey}]]></condition> <!-- {docKey} is a mandatory parameter to pass to the query -->
	<returnedFields> <!-- The list of document fields we want to return -->
		<field>player</field>
		<field>level</field>
		<field>lives</field>
		<field>score</field>
	</returnedFields>
</query>
  • No labels