Skip to content

Commit 38dc5d7

Browse files
authored
Update README.md
1 parent c39c630 commit 38dc5d7

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

README.md

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ CREATE TABLE todo (
3333
)
3434

3535
-- Located in Queries/Todo/Todo.sql
36-
DEFINE QUERY selectTodos AS
36+
selectTodos:
3737
SELECT * FROM todo;
3838
```
3939

@@ -178,7 +178,7 @@ feather queries add --name <some-name>
178178
179179
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.
180180
```sql
181-
DEFINE QUERY fetchUsers AS
181+
fetchUsers:
182182
SELECT * FROM user;
183183
```
184184

@@ -191,7 +191,7 @@ let users: [User] = try await query.execute()
191191
### Input and Output Types
192192
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.
193193
```sql
194-
DEFINE QUERY fetchUsers AS
194+
fetchUsers:
195195
SELECT user.*, COUNT(post.*) AS numberOfPosts
196196
OUTER JOIN post ON post.userId = user.id
197197
GROUP BY user.id;
@@ -211,7 +211,7 @@ FetchUsersOutput {
211211
### Inputs
212212
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.
213213
```sql
214-
DEFINE QUERY userPosts AS
214+
userPosts:
215215
SELECT * FROM post WHERE userId = ? AND date BETWEEN ? AND ?;
216216
```
217217

@@ -234,7 +234,8 @@ let posts = try await database.userQueries.userPosts.execute(with: UserPostInput
234234
### Naming
235235
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.
236236
```sql
237-
DEFINE QUERY queryName(input: InputName, output: OutputName) AS ...
237+
queryName(input: InputName, output: OutputName):
238+
...
238239
```
239240

240241
# Types
@@ -307,7 +308,7 @@ Most of the time we don't just have a query that has an input and output of simp
307308
They can be larger generated structs which can be a lot to type. To fix this typealiases are
308309
generated for a query to give them a simple readable name. For example
309310
```sql
310-
DEFINE QUERY latestExpenses AS
311+
latestExpenses:
311312
SELECT id, title, amount FROM expense
312313
WHERE date BETWEEN ? AND ?;
313314
```

0 commit comments

Comments
 (0)