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
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 input. In the following example we will join in the `post` table to get a users post count.
187
+
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 output. In the following example we will join in the `post` table to get a users post count.
188
188
```sql
189
189
DEFINE QUERY fetchUsers AS
190
190
SELECT user.*, COUNT(post.*) AS numberOfPosts
191
-
OUTER JOIN post ONpost.userId=user.id;
191
+
OUTER JOIN post ONpost.userId=user.id
192
+
GROUP BYuser.id;
192
193
```
193
194
194
195
The following `struct` would automatically be generated for the query. Since we used the syntax `user.*` it will embed the `User` struct instead of replicating it's columns. Any embeded table struct will also get a `@dynamicMemberLookup` method generated so it can be accessed directly like the other column values.
@@ -202,12 +203,6 @@ FetchUsersOutput {
202
203
}
203
204
```
204
205
205
-
### Naming
206
-
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.
207
-
```sql
208
-
DEFINE QUERY queryName(input: InputName, output: OutputName) AS ...
209
-
```
210
-
211
206
### Inputs
212
207
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
208
```sql
@@ -227,6 +222,12 @@ struct UserPostsInput {
227
222
let posts =tryawait database.userQueries.userPosts.execute(id: id, dateLower: lower, dateUpper: upper)
228
223
```
229
224
225
+
### Naming
226
+
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.
227
+
```sql
228
+
DEFINE QUERY queryName(input: InputName, output: OutputName) AS ...
229
+
```
230
+
230
231
# Types
231
232
SQLite is a unique SQL database engine in that it is fairly lawless when it comes to typing. SQLite will allow you create a column with an `INTEGER` and gladly insert a `TEXT` into it. It will even let you make up your own type names and will take them. Otter will not allow this and tends to operate more strictly like the table option `STRICT`. Only the core types that SQLite recognizes are usable for the column type.
0 commit comments