Skip to content

Commit 46a57f0

Browse files
committed
json docs
1 parent 0a58582 commit 46a57f0

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

examples/official-site/sqlpage/migrations/11_json.sql

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,11 @@ select ''json'' AS component, ''jsonlines'' AS type;
7676
select * from users where id = $user_id LIMIT 1;
7777
```
7878
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+
7984
### Result
8085
8186
```json
@@ -88,7 +93,8 @@ select * from users where id = $user_id LIMIT 1;
8893
'
8994
## Create a complex API endpoint
9095
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.
9298
9399
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.
94100
To build a json array out of rows from the database, you can use:
@@ -134,8 +140,11 @@ you can use
134140
'
135141
## Access query results in real-time with server-sent events
136142
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.
139148
140149
### SQL
141150

0 commit comments

Comments
 (0)