-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Getters and setters for the JSON type (#325)
* initial commit for JSON type support * comment on missing setters * get and set more inputs * formatting * add JSON example
- Loading branch information
1 parent
9f4f8de
commit 51311da
Showing
9 changed files
with
179 additions
and
29 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,44 @@ | ||
package main | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
|
||
"github.com/marcboeker/go-duckdb" | ||
) | ||
|
||
var db *sql.DB | ||
|
||
func main() { | ||
var err error | ||
db, err = sql.Open("duckdb", "?access_mode=READ_WRITE") | ||
|
||
check(err) | ||
defer db.Close() | ||
|
||
check(db.Ping()) | ||
|
||
var jsonArray duckdb.Composite[[]any] | ||
row := db.QueryRow(`SELECT json_array('foo', 'bar');`) | ||
check(row.Err()) | ||
check(row.Scan(&jsonArray)) | ||
|
||
log.Printf("first element: %s \n", jsonArray.Get()[0]) | ||
log.Printf("second element: %s \n", jsonArray.Get()[1]) | ||
|
||
var jsonMap duckdb.Composite[map[string]any] | ||
row = db.QueryRow(`SELECT '{"family": "anatidae", "species": ["duck", "goose"], "coolness": 42.42}'::JSON;`) | ||
check(row.Err()) | ||
check(row.Scan(&jsonMap)) | ||
|
||
log.Printf("family: %s", jsonMap.Get()["family"]) | ||
log.Printf("species: %s", jsonMap.Get()["species"]) | ||
log.Printf("coolness: %f", jsonMap.Get()["coolness"]) | ||
} | ||
|
||
func check(args ...interface{}) { | ||
err := args[len(args)-1] | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |
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
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