Skip to content

Instantly share code, notes, and snippets.

@taise
Created August 18, 2016 11:42
Show Gist options
  • Select an option

  • Save taise/3549102fb30f7717156dd5e5f1547fcd to your computer and use it in GitHub Desktop.

Select an option

Save taise/3549102fb30f7717156dd5e5f1547fcd to your computer and use it in GitHub Desktop.
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