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
Copy file name to clipboardExpand all lines: examples/official-site/sqlpage/migrations/11_json.sql
+12-3Lines changed: 12 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -76,6 +76,11 @@ select ''json'' AS component, ''jsonlines'' AS type;
76
76
select * from users where id = $user_id LIMIT 1;
77
77
```
78
78
79
+
> Note the `LIMIT 1` clause. The `jsonlines` type will send one JSON object per result row,
80
+
> separated only by a single newline character (\n).
81
+
> So if your query returns multiple rows, the result will not be a single valid JSON object,
82
+
> like most JSON parsers expect.
83
+
79
84
### Result
80
85
81
86
```json
@@ -88,7 +93,8 @@ select * from users where id = $user_id LIMIT 1;
88
93
'
89
94
## Create a complex API endpoint
90
95
91
-
This will create an API endpoint that will allow developers to easily query a list of users stored in your database.
96
+
You can create an API endpoint that will return a JSON value in any format you want,
97
+
to implement a complex API.
92
98
93
99
You should use [the json functions provided by your database](/blog.sql?post=JSON%20in%20SQL%3A%20A%20Comprehensive%20Guide) to form the value you pass to the `contents` property.
94
100
To build a json array out of rows from the database, you can use:
@@ -134,8 +140,11 @@ you can use
134
140
'
135
141
## Access query results in real-time with server-sent events
136
142
137
-
Using server-sent events, you can stream query results to the client in real-time.
138
-
This means you can build dynamic applications that will process data as it arrives.
143
+
Using server-sent events, you can stream large query results to the client in real-time,
144
+
row by row.
145
+
146
+
This allows building sophisticated dynamic applications that will start processing and displaying
147
+
the first rows of data in the browser while the database server is still processing the end of the query.
0 commit comments