예제 #1
0
파일: main.go 프로젝트: jwfang/builtin
func main() {
	notSet := &repo{Name: "not-set"}
	allSet := &repo{"allSet", b.String("the allset repo"), b.Bool(true), b.Int64(20), b.Float64(4.5)}
	zero := &repo{"", b.String(""), b.Bool(false), b.Int64(0), b.Float64(0)}

	allSet.print()
	notSet.print()
	zero.print()
}
예제 #2
0
파일: sql.go 프로젝트: jwfang/builtin
func (n *nullScanner) Scan(dest ...interface{}) error {
	replacements := map[int]interface{}{}

	for i, d := range dest {
		switch d.(type) {
		case *builtin.Booler:
			replacements[i] = dest[i]
			dest[i] = &sql.NullBool{}
		case *builtin.Stringer:
			replacements[i] = dest[i]
			dest[i] = &sql.NullString{}
		case *builtin.Int64er:
			replacements[i] = dest[i]
			dest[i] = &sql.NullInt64{}
		case *builtin.Float64er:
			replacements[i] = dest[i]
			dest[i] = &sql.NullFloat64{}
		}
	}

	err := n.Scanner.Scan(dest...)
	if err != nil {
		return err
	}

	for i, orig := range replacements {
		switch o := orig.(type) {
		case *builtin.Booler:
			if res := dest[i].(*sql.NullBool); res.Valid {
				*o = builtin.Bool(res.Bool)
			}
			dest[i] = o
		case *builtin.Stringer:
			if res := dest[i].(*sql.NullString); res.Valid {
				*o = builtin.String(res.String)
			}
			dest[i] = o
		case *builtin.Int64er:
			if res := dest[i].(*sql.NullInt64); res.Valid {
				*o = builtin.Int64(res.Int64)
			}
			dest[i] = o
		case *builtin.Float64er:
			if res := dest[i].(*sql.NullFloat64); res.Valid {
				*o = builtin.Float64(res.Float64)
			}
			dest[i] = o
		}
	}
	return nil
}