scopes
2015-12-13
scopes/postgres.go
Port over Postgres storage and tests. Do the minimum possible port of the code from auth to get Postgres working and make the tests run and pass again. This leaves a bug where the ErrScopeAlreadyExists type, when populatd from Postgres, contains the entire error string returned from the database, instead of parsing the ID itself out. Which is a thing we should do and add a test for.
| paddy@2 | 1 package scopes |
| paddy@2 | 2 |
| paddy@2 | 3 import ( |
| paddy@2 | 4 "database/sql" |
| paddy@2 | 5 ) |
| paddy@2 | 6 |
| paddy@2 | 7 func NewPostgres(conn string) (postgres, error) { |
| paddy@2 | 8 db, err := sql.Open("postgres", conn) |
| paddy@2 | 9 if err != nil { |
| paddy@2 | 10 return postgres{}, err |
| paddy@2 | 11 } |
| paddy@2 | 12 return postgres{db: db}, nil |
| paddy@2 | 13 } |
| paddy@2 | 14 |
| paddy@2 | 15 type postgres struct { |
| paddy@2 | 16 db *sql.DB |
| paddy@2 | 17 } |