Created
August 18, 2016 11:42
-
-
Save taise/3549102fb30f7717156dd5e5f1547fcd to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| package main | |
| import ( | |
| "fmt" | |
| "github.com/jinzhu/gorm" | |
| _ "github.com/lib/pq" | |
| ) | |
| type Schema struct { | |
| Nspname string | |
| } | |
| func main() { | |
| // FORMAT: postgres://user:pass@host:port/dbname | |
| var conninfo string = "postgres://user:pass@hoge.redshift.amazonaws.com:5439/db_name" | |
| db, err := gorm.Open("postgres", conninfo) | |
| if err != nil { | |
| panic(err) | |
| } | |
| defer db.Close() | |
| schemas := []Schema{} | |
| err = db.Debug().Table("pg_namespace").Order("nspname").Limit(10).Find(&schemas).Error | |
| if err != nil { | |
| panic(err) | |
| } | |
| for _, schema := range schemas { | |
| fmt.Println(schema.Nspname) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment