scopes

Paddy 2015-12-13

2:a64a25ae2db1 Go to Latest

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.

History
1 package scopeTypes
3 import (
4 "database/sql/driver"
6 "code.secondbit.org/pqarrays.hg"
7 )
9 func (s Scope) GetSQLTableName() string {
10 return "scopes"
11 }
13 func (s Scopes) Value() (driver.Value, error) {
14 ids := make(pqarrays.StringArray, 0, len(s))
15 for _, scope := range s {
16 ids = append(ids, scope.ID)
17 }
18 return ids.Value()
19 }
21 func (s *Scopes) Scan(value interface{}) error {
22 *s = (*s)[:0]
23 var ids pqarrays.StringArray
24 err := ids.Scan(value)
25 if err != nil {
26 return err
27 }
28 for _, id := range ids {
29 *s = append(*s, Scope{ID: id})
30 }
31 return nil
32 }