-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add support for
json
and jsonb
types
- Loading branch information
1 parent
58aa524
commit a35968c
Showing
9 changed files
with
176 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
version: 1.1.8 | ||
title: json decoding | ||
file: ./test/squirrel_test.gleam | ||
test_name: json_decoding_test | ||
--- | ||
import decode | ||
import gleam/pgo | ||
|
||
/// A row you get from running the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This type definition was generated automatically using v-test of the | ||
/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub type QueryRow { | ||
QueryRow(res: BitArray) | ||
} | ||
|
||
/// Runs the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This function was generated automatically using v-test of | ||
/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub fn query(db) { | ||
let decoder = | ||
decode.into({ | ||
use res <- decode.parameter | ||
QueryRow(res: res) | ||
}) | ||
|> decode.field(0, decode.bit_array) | ||
|
||
"select '{\"a\": 1}'::json as res" | ||
|> pgo.execute(db, [], decode.from(decoder, _)) | ||
} |
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,21 @@ | ||
--- | ||
version: 1.1.8 | ||
title: json encoding | ||
file: ./test/squirrel_test.gleam | ||
test_name: json_encoding_test | ||
--- | ||
import decode | ||
import gleam/pgo | ||
|
||
/// Runs the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This function was generated automatically using v-test of | ||
/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub fn query(db, arg_1) { | ||
let decoder = decode.map(decode.dynamic, fn(_) { Nil }) | ||
|
||
"insert into jsons(json) values ($1)" | ||
|> pgo.execute(db, [pgo.text(arg_1)], decode.from(decoder, _)) | ||
} |
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,36 @@ | ||
--- | ||
version: 1.1.8 | ||
title: jsonb decoding | ||
file: ./test/squirrel_test.gleam | ||
test_name: jsonb_decoding_test | ||
--- | ||
import decode | ||
import gleam/pgo | ||
|
||
/// A row you get from running the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This type definition was generated automatically using v-test of the | ||
/// > [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub type QueryRow { | ||
QueryRow(res: BitArray) | ||
} | ||
|
||
/// Runs the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This function was generated automatically using v-test of | ||
/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub fn query(db) { | ||
let decoder = | ||
decode.into({ | ||
use res <- decode.parameter | ||
QueryRow(res: res) | ||
}) | ||
|> decode.field(0, decode.bit_array) | ||
|
||
"select '{\"a\": 1}'::jsonb as res" | ||
|> pgo.execute(db, [], decode.from(decoder, _)) | ||
} |
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,21 @@ | ||
--- | ||
version: 1.1.8 | ||
title: jsonb encoding | ||
file: ./test/squirrel_test.gleam | ||
test_name: jsonb_encoding_test | ||
--- | ||
import decode | ||
import gleam/pgo | ||
|
||
/// Runs the `query` query | ||
/// defined in `query.sql`. | ||
/// | ||
/// > 🐿️ This function was generated automatically using v-test of | ||
/// > the [squirrel package](https://github.com/giacomocavalieri/squirrel). | ||
/// | ||
pub fn query(db, arg_1) { | ||
let decoder = decode.map(decode.dynamic, fn(_) { Nil }) | ||
|
||
"insert into jsons(jsonb) values($1)" | ||
|> pgo.execute(db, [pgo.text(arg_1)], decode.from(decoder, _)) | ||
} |
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
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