|
1 | 1 | # redshift-data-sql-driver |
2 | | -go sql driver for Redshift-Data API |
| 2 | + |
| 3 | +[](https://godoc.org/github.com/mashiike/redshift-data-sql-driver) |
| 4 | + |
| 5 | + |
| 6 | +[](https://goreportcard.com/report/mashiike/redshift-data-sql-driver) |
| 7 | +[](https://github.com/mashiike/redshift-data-sql-driver/blob/master/LICENSE) |
| 8 | + |
| 9 | +Redshift-Data API SQL Driver for Go's [database/sql](https://pkg.go.dev/database/sql) package |
| 10 | + |
| 11 | +## Usage |
| 12 | + |
| 13 | +for example: |
| 14 | + |
| 15 | +```go |
| 16 | +package main |
| 17 | + |
| 18 | +import ( |
| 19 | + "context" |
| 20 | + "database/sql" |
| 21 | + "log" |
| 22 | + |
| 23 | + _ "github.com/mashiike/redshift-data-sql-driver" |
| 24 | +) |
| 25 | + |
| 26 | +func main() { |
| 27 | + db, err := sql.Open("redshift-data", "workgroup(default)/dev?timeout=1m") |
| 28 | + if err != nil { |
| 29 | + log.Fatalln(err) |
| 30 | + } |
| 31 | + defer db.Close() |
| 32 | + rows, err := db.QueryContext( |
| 33 | + context.Background(), |
| 34 | + `SELECT table_schema,table_name,table_type FROM svv_tables WHERE table_schema not like :ignore_schema`, |
| 35 | + sql.Named("ignore_schema", "pg_%"), |
| 36 | + ) |
| 37 | + if err != nil { |
| 38 | + log.Fatalln(err) |
| 39 | + } |
| 40 | + for rows.Next() { |
| 41 | + var schema, name, tableType string |
| 42 | + err := rows.Scan(&schema, &name, &tableType) |
| 43 | + if err != nil { |
| 44 | + log.Println(err) |
| 45 | + return |
| 46 | + } |
| 47 | + log.Printf("%s.%s\t%s", schema, name, tableType) |
| 48 | + } |
| 49 | +} |
| 50 | +``` |
| 51 | + |
| 52 | +The pattern for specifying DSNs is as follows |
| 53 | + |
| 54 | +- with redshift serverless: `workgroup([name])/[database]` |
| 55 | +- with provisoned cluster: `[dbuser]@cluster([name])/[database]` |
| 56 | +- with AWS Secrets Manager: `arn:aws:secretsmanager:us-east-1:0123456789012:secret:redshift` |
| 57 | + |
| 58 | +The DSN parameters include |
| 59 | + |
| 60 | +- `timeout`: Timeout for query execution. default = `15m0s` |
| 61 | +- `polling`: Interval to check for the end of a running query. default = `10ms` |
| 62 | +- `region`: Redshift Data API's region. Default is environment setting |
| 63 | + |
| 64 | +Parameter settings are in the format of URL query parameter |
| 65 | + |
| 66 | +`workgroup(default)/dev?timeout=1m&polling=1ms` |
| 67 | + |
| 68 | +## Unsupported Features |
| 69 | + |
| 70 | +The following functions are not available |
| 71 | + |
| 72 | +### [BeginTx](https://pkg.go.dev/database/sql#DB.BeginTx),[Begin](https://pkg.go.dev/database/sql#DB.Begin) |
| 73 | + |
| 74 | +The Redshift Data API does not have an interface for pasting transactions and querying sequentially. |
| 75 | +Therefore, transactional functionality is not available. |
| 76 | + |
| 77 | +### [Prepare](https://pkg.go.dev/database/sql#DB.Prepare) |
| 78 | + |
| 79 | +Prepared Statements were not supported because the Redshift Data API does not have the concept of connecting to a DB. |
| 80 | + |
| 81 | +## LICENSE |
| 82 | + |
| 83 | +MIT |
0 commit comments