Skip to content

Commit a548471

Browse files
authored
Update README.md
1 parent f4a165c commit a548471

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

README.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,11 +184,12 @@ let users: [User] = try await query.execute()
184184
```
185185

186186
### Input and Output Types
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 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.
188188
```sql
189189
DEFINE QUERY fetchUsers AS
190190
SELECT user.*, COUNT(post.*) AS numberOfPosts
191-
OUTER JOIN post ON post.userId = user.id;
191+
OUTER JOIN post ON post.userId = user.id
192+
GROUP BY user.id;
192193
```
193194

194195
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 {
202203
}
203204
```
204205

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-
211206
### Inputs
212207
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.
213208
```sql
@@ -227,6 +222,12 @@ struct UserPostsInput {
227222
let posts = try await database.userQueries.userPosts.execute(id: id, dateLower: lower, dateUpper: upper)
228223
```
229224

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+
230231
# Types
231232
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.
232233
| SQLite | Swift |

0 commit comments

Comments
 (0)