cubicweb/web/wdoc/tut_rql_en.rst
changeset 12792 e2cdb1be6bd9
parent 11057 0b59724cb3f2
equal deleted inserted replaced
12791:4564ecfc0134 12792:e2cdb1be6bd9
    53 
    53 
    54   * `=` is the default comparison operator
    54   * `=` is the default comparison operator
    55 
    55 
    56   * `LIKE` / `~=` permits use of the special character `%` in a string to tell
    56   * `LIKE` / `~=` permits use of the special character `%` in a string to tell
    57     the string must begin or end with a prefix or suffix (as SQL LIKE operator) ::
    57     the string must begin or end with a prefix or suffix (as SQL LIKE operator) ::
    58     
    58 
    59       Any X WHERE X name ~= 'Th%'
    59       Any X WHERE X name ~= 'Th%'
    60       Any X WHERE X name LIKE '%lt'
    60       Any X WHERE X name LIKE '%lt'
    61 
    61 
    62   * `IN` permits to give a list of possible values ::
    62   * `IN` permits to give a list of possible values ::
    63 
    63 
    67 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    67 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    68 ::
    68 ::
    69 
    69 
    70   [DISTINCT] <entity type> V1(, V2)*
    70   [DISTINCT] <entity type> V1(, V2)*
    71   [GROUPBY V1(, V2)*]  [ORDERBY <orderterms>]
    71   [GROUPBY V1(, V2)*]  [ORDERBY <orderterms>]
    72   [WHERE <restriction>] 
    72   [WHERE <restriction>]
    73   [LIMIT <value>] [OFFSET <value>]
    73   [LIMIT <value>] [OFFSET <value>]
    74 
    74 
    75 :entity type:
    75 :entity type:
    76   Type of the selected variable(s). You'll usually use `Any` type to not specify
    76   Type of the selected variable(s). You'll usually use `Any` type to not specify
    77   any type.
    77   any type.
    93 here. Available entity types are :
    93 here. Available entity types are :
    94 
    94 
    95 :Person:
    95 :Person:
    96   ::
    96   ::
    97 
    97 
    98 	name      (String, required) 
    98     name      (String, required)
    99 	birthday (Date)
    99     birthday (Date)
   100 
   100 
   101 
   101 
   102 :Company:
   102 :Company:
   103   ::
   103   ::
   104 
   104 
   105 	name   (String)
   105     name   (String)
   106 
   106 
   107 
   107 
   108 :Note:
   108 :Note:
   109   ::
   109   ::
   110 
   110 
   111 	diem (Date)
   111     diem (Date)
   112 	type (String)
   112     type (String)
   113 
   113 
   114 
   114 
   115 And relations between those entities: ::
   115 And relations between those entities: ::
   116 
   116 
   117 	Person  works_for    Company
   117     Person  works_for    Company
   118 	Person  evaluated_by Note
   118     Person  evaluated_by Note
   119 	Company evaluated_by Note
   119     Company evaluated_by Note
   120 
   120 
   121 
   121 
   122 Meta-data
   122 Meta-data
   123 ~~~~~~~~~
   123 ~~~~~~~~~
   124 Every entities'type have the following meta-data:
   124 Every entities'type have the following meta-data:
   137 A user's entity has the following schema:
   137 A user's entity has the following schema:
   138 
   138 
   139 :CWUser:
   139 :CWUser:
   140   ::
   140   ::
   141 
   141 
   142 	login  	  (String) not null
   142     login        (String) not null
   143 	password  (Password)
   143     password  (Password)
   144 	firstname (String)
   144     firstname (String)
   145 	surname   (String)
   145     surname   (String)
   146 
   146 
   147 
   147 
   148 Basis queries
   148 Basis queries
   149 -------------
   149 -------------
   150 0. *Every persons* ::
   150 0. *Every persons* ::
   151    
   151 
   152       Person X
   152       Person X
   153 
   153 
   154    or ::
   154    or ::
   155 
   155 
   156       Any X WHERE X is Person
   156       Any X WHERE X is Person
   203 
   203 
   204       Any X WHERE X evaluated_by N, N eid 43
   204       Any X WHERE X evaluated_by N, N eid 43
   205 
   205 
   206 
   206 
   207 7. *Every persons order by birthday from the youngest to the oldest* ::
   207 7. *Every persons order by birthday from the youngest to the oldest* ::
   208    
   208 
   209       Person X ORDERBY D DESC WHERE X birthday D
   209       Person X ORDERBY D DESC WHERE X birthday D
   210 
   210 
   211    Notice you've to define a variable using the birthday relation to use it in the
   211    Notice you've to define a variable using the birthday relation to use it in the
   212    sort term. 
   212    sort term.
   213 
   213 
   214 
   214 
   215 8. *Number of persons working for each known company* ::
   215 8. *Number of persons working for each known company* ::
   216    
   216 
   217       Any S, COUNT(X) GROUPBY S WHERE X works_for S
   217       Any S, COUNT(X) GROUPBY S WHERE X works_for S
   218 
   218 
   219    Notice you've that since you're writing a grouped query on S, X have to be
   219    Notice you've that since you're writing a grouped query on S, X have to be
   220    either grouped as well or used in an aggregat function (as in this example).
   220    either grouped as well or used in an aggregat function (as in this example).
   221 
   221 
   222 
   222 
   223    
   223 
   224 Advanced
   224 Advanced
   225 --------
   225 --------
   226 0. *Person with no name specified (i.e NULL)* ::
   226 0. *Person with no name specified (i.e NULL)* ::
   227 
   227 
   228       Person P WHERE P name NULL
   228       Person P WHERE P name NULL