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.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/types/scope_postgres.go	Sun Dec 13 20:42:48 2015 -0800
     1.3 @@ -0,0 +1,32 @@
     1.4 +package scopeTypes
     1.5 +
     1.6 +import (
     1.7 +	"database/sql/driver"
     1.8 +
     1.9 +	"code.secondbit.org/pqarrays.hg"
    1.10 +)
    1.11 +
    1.12 +func (s Scope) GetSQLTableName() string {
    1.13 +	return "scopes"
    1.14 +}
    1.15 +
    1.16 +func (s Scopes) Value() (driver.Value, error) {
    1.17 +	ids := make(pqarrays.StringArray, 0, len(s))
    1.18 +	for _, scope := range s {
    1.19 +		ids = append(ids, scope.ID)
    1.20 +	}
    1.21 +	return ids.Value()
    1.22 +}
    1.23 +
    1.24 +func (s *Scopes) Scan(value interface{}) error {
    1.25 +	*s = (*s)[:0]
    1.26 +	var ids pqarrays.StringArray
    1.27 +	err := ids.Scan(value)
    1.28 +	if err != nil {
    1.29 +		return err
    1.30 +	}
    1.31 +	for _, id := range ids {
    1.32 +		*s = append(*s, Scope{ID: id})
    1.33 +	}
    1.34 +	return nil
    1.35 +}