当前位置: 首页>>代码示例>>Golang>>正文


Golang driver.Value函数代码示例

本文整理汇总了Golang中database/sql/driver.Value函数的典型用法代码示例。如果您正苦于以下问题:Golang Value函数的具体用法?Golang Value怎么用?Golang Value使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Value函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Value

// Value implements the driver.Value interface.
func (c Command) Value() (driver.Value, error) {
	raw, err := json.Marshal(c)
	if err != nil {
		return nil, err
	}
	return driver.Value(raw), nil
}
开发者ID:carriercomm,项目名称:empire,代码行数:8,代码来源:processes.go

示例2: Next

// DATE, DATETIME, TIMESTAMP are treated as they are in Local time zone (this
// can be changed globaly using SetLocation function).
func (r *rowsRes) Next(dest []driver.Value) error {
	if r.my == nil {
		return io.EOF // closed before
	}
	err := r.my.ScanRow(r.row)
	if err == nil {
		if r.simpleQuery == textQuery {
			// workaround for time.Time from text queries
			for i, f := range r.my.Fields() {
				if r.row[i] != nil {
					switch f.Type {
					case native.MYSQL_TYPE_TIMESTAMP, native.MYSQL_TYPE_DATETIME,
						native.MYSQL_TYPE_DATE, native.MYSQL_TYPE_NEWDATE:
						r.row[i] = r.row.ForceTime(i, location)
					}
				}
			}
		}
		for i, d := range r.row {
			dest[i] = driver.Value(d)
		}
		return nil
	}
	if err != io.EOF {
		return errFilter(err)
	}
	if r.simpleQuery != nil && r.simpleQuery != textQuery {
		if err = r.simpleQuery.Delete(); err != nil {
			return errFilter(err)
		}
	}
	r.my = nil
	return io.EOF
}
开发者ID:whosonfirst,项目名称:go-whosonfirst-rtree,代码行数:36,代码来源:driver.go

示例3: Next

func (r *Rows) Next(dest []driver.Value) error {
	more := r.rows.Next()
	if !more {
		if r.rows.Err() == nil {
			return io.EOF
		} else {
			return r.rows.Err()
		}
	}

	values, err := r.rows.Values()
	if err != nil {
		return err
	}

	if len(dest) < len(values) {
		fmt.Printf("%d: %#v\n", len(dest), dest)
		fmt.Printf("%d: %#v\n", len(values), values)
		return errors.New("expected more values than were received")
	}

	for i, v := range values {
		dest[i] = driver.Value(v)
	}

	return nil
}
开发者ID:josephwinston,项目名称:flynn,代码行数:27,代码来源:sql.go

示例4: Value

// Convert to SQL driver value.
func (pys Pinyins) Value() (value driver.Value, err error) {
	var buf []byte
	var ret = []byte{'{'}
	for _, py := range pys {
		for _, b := range []byte(py) {
			if b >= 65 && b <= 90 { // A - Z
				b += 32
			}
			if b >= 97 && b <= 122 { // a - z
				buf = append(buf, b)
			}
		}
		if len(buf) > 0 {
			buf = append(buf, ',')
			ret = append(ret, buf...)
			buf = nil
		}
	}
	if ret[len(ret)-1] == ',' {
		ret[len(ret)-1] = '}'
	} else {
		ret = append(ret, '}')
	}
	value = driver.Value(string(ret))
	return
}
开发者ID:caiguanhao,项目名称:gopinyin,代码行数:27,代码来源:gopinyin.go

示例5: TestFloat32_Value

func TestFloat32_Value(t *testing.T) {
	expect, val := Float32(10.5), driver.Value(10.5)
	var f Float32
	f.Scan(val)
	if f != expect {
		t.Errorf("Expect %f, but %f", expect, f)
	}
}
开发者ID:hirokidaichi,项目名称:genmai,代码行数:8,代码来源:type_test.go

示例6: Value

// Value lets intArrays be inserted into PG
func (a IntArray) Value() (val driver.Value, err error) {
	str := "{"
	for _, i := range a {
		str += strconv.Itoa(i) + ","
	}
	str += "}"

	val = driver.Value(str)

	return
}
开发者ID:fortytw2,项目名称:eden,代码行数:12,代码来源:int_array.go

示例7: Value

// Value function is called when the data is inserted on the database
func (e EncryptedString) Value() (driver.Value, error) {
	// Calling KMS
	crypted, err := encrypt([]byte(e), svc, keyID)

	if err != nil {
		return nil, err
	}

	// The byte array is stored as a base64 string on the database
	return driver.Value(base64.StdEncoding.EncodeToString(crypted)), nil
}
开发者ID:dimiro1,项目名称:experiments,代码行数:12,代码来源:main.go

示例8: Value

// Value implements the driver.Value interface.
func (c Certs) Value() (driver.Value, error) {
	if c == nil {
		return nil, nil
	}

	raw, err := json.Marshal(c)
	if err != nil {
		return nil, err
	}

	return driver.Value(raw), nil
}
开发者ID:iserko,项目名称:empire,代码行数:13,代码来源:apps.go

示例9: Query

func (s *stmt) Query(args []driver.Value) (driver.Rows, error) {
	s.conn.Lock()
	defer s.conn.Unlock()

	// create stement
	st, err := s.conn.tx.Prepare(s.query)
	if err != nil {
		return nil, err
	}
	defer st.Close()

	// query rows
	var iargs []interface{}
	for _, arg := range args {
		iargs = append(iargs, arg)
	}
	rs, err := st.Query(iargs...)
	if err != nil {
		return nil, err
	}
	defer rs.Close()

	// build all rows in memory, prevent statement lock
	rows := &rows{}
	rows.cols, err = rs.Columns()
	if err != nil {
		return nil, err
	}
	for rs.Next() {
		values := make([]interface{}, len(rows.cols))
		for i := range values {
			values[i] = new(interface{})
		}
		if err := rs.Scan(values...); err != nil {
			return rows, err
		}
		row := make([]driver.Value, len(rows.cols))
		for i, v := range values {
			row[i] = driver.Value(v)
		}
		rows.rows = append(rows.rows, row)
	}
	if err := rs.Err(); err != nil {
		return rows, err
	}
	return rows, nil
}
开发者ID:DATA-DOG,项目名称:go-txdb,代码行数:47,代码来源:db.go

示例10: TestLineValue

func TestLineValue(t *testing.T) {
	for _, c := range []struct {
		Input    Line
		Expected driver.Value
	}{
		{
			Input:    Line{{0, 0}, {1, 1}},
			Expected: driver.Value(`LINESTRING(0 0, 1 1)`),
		},
	} {
		val, err := c.Input.Value()
		if err != nil {
			t.Fatal(err)
		}
		if val != c.Expected {
			t.Fatalf("expected %v, got %v", c.Expected, val)
		}
	}
}
开发者ID:yanbai1990,项目名称:geo,代码行数:19,代码来源:line_test.go

示例11: Next

func (r *rows) Next(dest []sqldriver.Value) error {
	if r.step >= r.Resultset.RowNumber() {
		return io.EOF
	} else if r.step == -1 {
		return io.ErrUnexpectedEOF
	}

	for i := 0; i < r.Resultset.ColumnNumber(); i++ {
		value, err := r.Resultset.GetValue(r.step, i)
		if err != nil {
			return err
		}

		dest[i] = sqldriver.Value(value)
	}

	r.step++

	return nil
}
开发者ID:blalor,项目名称:go-mysql,代码行数:20,代码来源:driver.go

示例12: Value

func (b Hostname) Value() (driver.Value, error) {
	return driver.Value(string(b)), nil
}
开发者ID:hartsock,项目名称:go-swagger,代码行数:3,代码来源:default.go

示例13: Value

// Value implements the Valuer interface in database/sql/driver package.
func (a IntArray) Value() (driver.Value, error) {
	return driver.Value(string(String(fmt.Sprintf("%#v", a)).Replace("dna.IntArray", ""))), nil
}
开发者ID:olragon,项目名称:dna,代码行数:4,代码来源:int_array.go

示例14: Value

// Value implements the driver.Value interface.
func (s DeploymentStatus) Value() (driver.Value, error) {
	return driver.Value(s.String()), nil
}
开发者ID:carriercomm,项目名称:empire,代码行数:4,代码来源:deployments.go

示例15: Value

// Value implements the Valuer interface in database/sql/driver package.
func (i Int) Value() (driver.Value, error) {
	return driver.Value(int64(i.ToPrimitiveValue())), nil
}
开发者ID:olragon,项目名称:dna,代码行数:4,代码来源:int.go


注:本文中的database/sql/driver.Value函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。