Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[doc] database: Added selection chapter

  • Loading branch information...
commit 119cbc3ebab484b9b467251c7eb65e3ea321e320 1 parent b94c509
@BourgerieQuentin BourgerieQuentin authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 opadoc/manual.omd/en/ref_database.omd
View
39 opadoc/manual.omd/en/ref_database.omd
@@ -102,6 +102,7 @@ If you do not define a default value, Opa uses the following strategy:
- the default value for a record is the record of default values;
- the default value for a sum type is the case which looks most like an empty case (e.g. `{none}` for `option`, `{nil}` for list, etc.)
+
Updating
--------
@@ -219,6 +220,44 @@ Furthermore you can specify some querying options:
// Access to a submap where keys are lesser than 9 and greater than 4
intmap(stored) submap = /dbname/imap[< 9 and > 4]
+Selection
+--------
+
+We saw how we can request database sets and maps to obtain a sub-set of declared
+dbset and map. But often we need only have a subset of fields stored at database
+rows. We already saw we can access to subpath of a given path :
+
+ // Access to /my_db/r
+ stored x = /my_db/r
+ // Access to the /y sub-path of /my_db/r
+ int x = /my_db/r/x
+
+If we want to access to both supath /x and /y of path /my_db/r we can write
+something like that :
+
+ {int x, int y} x = {x : /my_db/r/x, y : /my_db/r/y}
+
+But they have a more consice and optimized way to get these datas :
+
+ // This path access means 'select fields x and y in path /my_db/r'
+ {int x, int y} x = /my_db/r.{x, y}
+
+Conversely, you could use these kinds of projection on database sets and maps,
+below some examples:
+
+ // Access of /v sub-path of a set access with primary key
+ string result = /dbname/set[x == 10]/v
+
+ // Access of both sub-path /x and /v of a set access with primary key
+ {int x, string v} result = /dbname/set[x == 10].{x, v}
+
+ // Access of /v sub-paths of a set access
+ dbset(string, _) results = /dbname/set[x > 10, y > 0, v in ["foo", "bar"]]/v
+
+ // Access of both sub-paths /x and /v of a set access
+ dbset({int x, string v}, _) results = /dbname/set[x > 10, y > 0, v in ["foo", "bar"]].{x, v}
+
+
Manipulating paths
------------------
Please sign in to comment.
Something went wrong with that request. Please try again.