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: CHANGELOG.md
+3Lines changed: 3 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,9 @@
9
9
- New `initial_search_value` property in the table component to pre-fill the search bar with a value. This allows to display the table rows that will initially be filtered out by the search bar.
10
10
- Fix autoplay of carousels when embedded in a card.
11
11
- Allow setting image width and height in carousels, in order to avoid differently sized images to cause layout janking when going through them.
12
+
- Many improvements to the [json](https://sql.datapage.app/component.sql?component=json) component, making it easier and faster than ever to build REST APIs entirely in SQL.
13
+
-**Ease of use** : the component can now be used to automatically format any query result as a json array, without manually using your database''s json functions.
14
+
-**server-sent events** : the component can now be used to stream query results to the client in real-time using server-sent events.
12
15
13
16
## 0.29.0 (2024-09-25)
14
17
- New columns component: `columns`. Useful to display a comparison between items, or large key figures to an user.
'For advanced users, allows you to easily build an API over your database.
5
7
The json component responds to the current HTTP request with a JSON object.
6
8
This component must appear at the top of your SQL file, before any other data has been sent to the browser.',
7
9
'code',
8
10
'0.9.0'
9
11
);
12
+
10
13
-- Insert the parameters for the http_header component into the parameter table
11
-
INSERT INTO parameter (
14
+
INSERT INTO
15
+
parameter (
12
16
component,
13
17
name,
14
18
description,
15
19
type,
16
20
top_level,
17
21
optional
18
22
)
19
-
VALUES (
23
+
VALUES
24
+
(
20
25
'json',
21
26
'contents',
22
-
'The JSON payload to send. You should use your database''s built-in json functions to build the value to enter here.',
27
+
'A single JSON payload to send. You can use your database''s built-in json functions to build the value to enter here. If not provided, the contents will be taken from the next SQL statements and rendered as a JSON array.',
23
28
'TEXT',
24
29
TRUE,
25
-
FALSE
30
+
TRUE
31
+
),
32
+
(
33
+
'json',
34
+
'type',
35
+
'The type of the JSON payload to send. Defaults to "array" (each query result is rendered as a JSON object in the array). Other possible values are "jsonlines" (each query result is rendered as a JSON object in a new line, without a top-level array) and "sse" (each query result is rendered as a JSON object in a new line, prefixed by "data: ", which allows you to read the results as server-sent events in real-time from javascript).',
36
+
'TEXT',
37
+
TRUE,
38
+
TRUE
26
39
);
40
+
27
41
-- Insert an example usage of the http_header component into the example table
28
-
INSERT INTO example (component, description)
29
-
VALUES (
42
+
INSERT INTO
43
+
example (component, description)
44
+
VALUES
45
+
(
46
+
'json',
47
+
'
48
+
## Send query results as a JSON array
49
+
50
+
### SQL
51
+
52
+
```sql
53
+
select ''json'' AS component;
54
+
select * from users;
55
+
```
56
+
57
+
### Result
58
+
59
+
```json
60
+
[
61
+
{"username":"James","userid":1},
62
+
{"username":"John","userid":2}
63
+
]
64
+
```
65
+
'
66
+
),
67
+
(
68
+
'json',
69
+
'
70
+
## Send a single JSON object
71
+
72
+
### SQL
73
+
74
+
```sql
75
+
select ''json'' AS component, ''jsonlines'' AS type;
76
+
select * from users where id = $user_id LIMIT 1;
77
+
```
78
+
79
+
### Result
80
+
81
+
```json
82
+
{ "username":"James", "userid":1 }
83
+
```
84
+
'
85
+
),
86
+
(
30
87
'json',
31
88
'
32
-
Creates an API endpoint that will allow developers to easily query a list of users stored in your database.
89
+
## Create a complex API endpoint
90
+
91
+
This will create an API endpoint that will allow developers to easily query a list of users stored in your database.
33
92
34
93
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.
35
94
To build a json array out of rows from the database, you can use:
@@ -69,4 +128,30 @@ you can use
69
128
- the [`request_method` function](/functions.sql?function=request_method#function) to differentiate between GET and POST requests,
70
129
- and the [`path` function](/functions.sql?function=path#function) to extract the `:id` parameter from the URL.
71
130
'
72
-
);
131
+
),
132
+
(
133
+
'json',
134
+
'
135
+
## Access query results in real-time with server-sent events
136
+
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.
0 commit comments