https://github.com/mashiike/redshift-data-sql-driver
go sql driver for Redshift-Data API
https://github.com/mashiike/redshift-data-sql-driver
go redshift sql-driver
Last synced: about 1 month ago
JSON representation
go sql driver for Redshift-Data API
- Host: GitHub
- URL: https://github.com/mashiike/redshift-data-sql-driver
- Owner: mashiike
- License: mit
- Created: 2022-11-11T04:34:22.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-28T13:31:10.000Z (about 1 year ago)
- Last Synced: 2025-04-30T07:05:01.076Z (about 1 month ago)
- Topics: go, redshift, sql-driver
- Language: Go
- Homepage:
- Size: 63.5 KB
- Stars: 8
- Watchers: 1
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# redshift-data-sql-driver
[](https://godoc.org/github.com/mashiike/redshift-data-sql-driver)


[](https://goreportcard.com/report/mashiike/redshift-data-sql-driver)
[](https://github.com/mashiike/redshift-data-sql-driver/blob/master/LICENSE)Redshift-Data API SQL Driver for Go's [database/sql](https://pkg.go.dev/database/sql) package
## Usage
for example:
```go
package mainimport (
"context"
"database/sql"
"log"_ "github.com/mashiike/redshift-data-sql-driver"
)func main() {
db, err := sql.Open("redshift-data", "workgroup(default)/dev?timeout=1m")
if err != nil {
log.Fatalln(err)
}
defer db.Close()
rows, err := db.QueryContext(
context.Background(),
`SELECT table_schema,table_name,table_type FROM svv_tables WHERE table_schema not like :ignore_schema`,
sql.Named("ignore_schema", "pg_%"),
)
if err != nil {
log.Fatalln(err)
}
for rows.Next() {
var schema, name, tableType string
err := rows.Scan(&schema, &name, &tableType)
if err != nil {
log.Println(err)
return
}
log.Printf("%s.%s\t%s", schema, name, tableType)
}
}
```The pattern for specifying DSNs is as follows
- with redshift serverless: `workgroup([name])/[database]`
- with provisoned cluster: `[dbuser]@cluster([name])/[database]`
- with AWS Secrets Manager: `arn:aws:secretsmanager:us-east-1:0123456789012:secret:redshift`The DSN parameters include
- `timeout`: Timeout for query execution. default = `15m0s`
- `polling`: Interval to check for the end of a running query. default = `10ms`
- `region`: Redshift Data API's region. Default is environment settingParameter settings are in the format of URL query parameter
`workgroup(default)/dev?timeout=1m&polling=1ms`
### Transaction Notes
The Redshift Data API does not have an interface for pasting transactions and querying sequentially.
Therefore, we have implemented an unusual implementation.```go
package mainimport (
"context"
"database/sql"
"log"_ "github.com/mashiike/redshift-data-sql-driver"
)func main() {
db, err := sql.Open("redshift-data", "workgroup(default)/dev?timeout=1m")
if err != nil {
log.Fatalln(err)
}
defer db.Close()
tx, err := db.BeginTx(context.Background(), nil)
if err != nil {
log.Fatalln(err)
}
tx.ExecContext(context.Background(), "INSERT INTO foo VALUES (1)")
tx.ExecContext(context.Background(), "INSERT INTO foo VALUES (2)")
tx.ExecContext(context.Background(), "INSERT INTO foo VALUES (3)")
tx.Commit() // BatchExecuteStatement API is called here, and the queries called during the transaction are executed together
}
```Also, because the interface does not match, `Query` and `QueryContext` in the transaction are not supported.
`Exec` and `ExecContext` in the transaction are not supported.## Unsupported Features
The following functions are not available
### [Prepare](https://pkg.go.dev/database/sql#DB.Prepare)
Prepared Statements were not supported because the Redshift Data API does not have the concept of connecting to a DB.
## LICENSE
MIT