You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Open the file that was created in `/Queries`, it should be blank. Individual queries can be defined using the `DEFINE` keyword. At the moment queries can only have one statement.
In the example above, since we selected all columns from a single table the query will return the `User` struct that was generated for the table. If additional columns are selected a new structure will be generated to match the selected columns. In the following example we will join in the `post` table to get a users post count.
193
193
```sql
194
-
DEFINE QUERY fetchUsersAS
194
+
fetchUsers:
195
195
SELECT user.*, COUNT(post.*) AS numberOfPosts
196
196
OUTER JOIN post ONpost.userId=user.id
197
197
GROUP BYuser.id;
@@ -211,7 +211,7 @@ FetchUsersOutput {
211
211
### Inputs
212
212
When a query has multiple inputs it will have a struct generated for it's inputs similar to the output. Also, so the input struct does not have to be initialized everytime, an extension will be created that takes each parameter individually, rather then the full type.
213
213
```sql
214
-
DEFINE QUERY userPostsAS
214
+
userPosts:
215
215
SELECT*FROM post WHERE userId = ? ANDdate BETWEEN ? AND ?;
The `FetchUsersOutput` name, while clear where it came from, is not too great if we want to store it in a view model or model within our app. Some queries we want to give it a better name that has more meaning. In the `DEFINE` statement we can specify a name for the inputs and outputs.
236
236
```sql
237
-
DEFINE QUERY queryName(input: InputName, output: OutputName) AS ...
237
+
queryName(input: InputName, output: OutputName):
238
+
...
238
239
```
239
240
240
241
# Types
@@ -307,7 +308,7 @@ Most of the time we don't just have a query that has an input and output of simp
307
308
They can be larger generated structs which can be a lot to type. To fix this typealiases are
308
309
generated for a query to give them a simple readable name. For example
0 commit comments