-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #791 from etehtsea/enh-pg-out-example
feat(outbound-pg): Reuse connection during request lifecycle
- Loading branch information
Showing
6 changed files
with
159 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# Spin Outbound PostgreSQL example | ||
|
||
This example shows how to access a PostgreSQL database from Spin component. | ||
|
||
## Spin up | ||
|
||
From example root: | ||
|
||
``` | ||
createdb spin_dev | ||
psql -d spin_dev -f db/testdata.sql | ||
RUST_LOG=spin=trace spin build --up | ||
``` | ||
|
||
Curl the read route: | ||
|
||
``` | ||
$ curl -i localhost:3000/read | ||
HTTP/1.1 200 OK | ||
content-length: 501 | ||
date: Sun, 25 Sep 2022 15:45:02 GMT | ||
Found 2 article(s) as follows: | ||
article: Article { | ||
id: 1, | ||
title: "My Life as a Goat", | ||
content: "I went to Nepal to live as a goat, and it was much better than being a butler.", | ||
authorname: "E. Blackadder", | ||
} | ||
article: Article { | ||
id: 2, | ||
title: "Magnificent Octopus", | ||
content: "Once upon a time there was a lovely little sausage.", | ||
authorname: "S. Baldrick", | ||
} | ||
(Column info: id:DbDataType::Int32, title:DbDataType::Str, content:DbDataType::Str, authorname:DbDataType::Str) | ||
``` | ||
|
||
Curl the write route: | ||
|
||
``` | ||
$ curl -i localhost:3000/write | ||
HTTP/1.1 200 OK | ||
content-length: 9 | ||
date: Sun, 25 Sep 2022 15:46:22 GMT | ||
Count: 3 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
CREATE TABLE articletest ( | ||
id integer not null, | ||
title varchar(40) not null, | ||
content varchar(8000) not null, | ||
authorname varchar(40) not null | ||
id integer GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, | ||
title varchar(40) NOT NULL, | ||
content text NOT NULL, | ||
authorname varchar(40) NOT NULL | ||
); | ||
|
||
INSERT INTO articletest VALUES (1, 'My Life as a Goat', 'I went to Nepal to live as a goat, and it was much better than being a butler.', 'E. Blackadder'); | ||
INSERT INTO articletest VALUES (2, 'Magnificent Octopus', 'Once upon a time there was a lovely little sausage.', 'S. Baldrick'); | ||
INSERT INTO articletest (title, content, authorname) VALUES | ||
( | ||
'My Life as a Goat', | ||
'I went to Nepal to live as a goat, and it was much better than being a butler.', | ||
'E. Blackadder' | ||
), | ||
( | ||
'Magnificent Octopus', | ||
'Once upon a time there was a lovely little sausage.', | ||
'S. Baldrick' | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters