scopes
2015-12-13
scopes/types/scope_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 scopeTypes |
| paddy@2 | 2 |
| paddy@2 | 3 import ( |
| paddy@2 | 4 "database/sql/driver" |
| paddy@2 | 5 |
| paddy@2 | 6 "code.secondbit.org/pqarrays.hg" |
| paddy@2 | 7 ) |
| paddy@2 | 8 |
| paddy@2 | 9 func (s Scope) GetSQLTableName() string { |
| paddy@2 | 10 return "scopes" |
| paddy@2 | 11 } |
| paddy@2 | 12 |
| paddy@2 | 13 func (s Scopes) Value() (driver.Value, error) { |
| paddy@2 | 14 ids := make(pqarrays.StringArray, 0, len(s)) |
| paddy@2 | 15 for _, scope := range s { |
| paddy@2 | 16 ids = append(ids, scope.ID) |
| paddy@2 | 17 } |
| paddy@2 | 18 return ids.Value() |
| paddy@2 | 19 } |
| paddy@2 | 20 |
| paddy@2 | 21 func (s *Scopes) Scan(value interface{}) error { |
| paddy@2 | 22 *s = (*s)[:0] |
| paddy@2 | 23 var ids pqarrays.StringArray |
| paddy@2 | 24 err := ids.Scan(value) |
| paddy@2 | 25 if err != nil { |
| paddy@2 | 26 return err |
| paddy@2 | 27 } |
| paddy@2 | 28 for _, id := range ids { |
| paddy@2 | 29 *s = append(*s, Scope{ID: id}) |
| paddy@2 | 30 } |
| paddy@2 | 31 return nil |
| paddy@2 | 32 } |