Пример #1
0
// If record exists with this key, it is overwritten
func (connection *Connection) Put(primary_key string, columns ColumnMap) (err os.Error) {
	fmt.Printf("storing %v => %v\n", primary_key, columns)
	cols := C.xtc_mapnew()
	defer C.xtc_mapdel(cols)
	for name, value := range columns {
		C.xtc_mapput(cols, C.CString(name), C.CString(value))
	}
	if C.xtcrdb_tblput(connection.Tyrant, C.CString(primary_key), cols) == 0 {
		return os.NewError(connection.ErrorMessage())
	}
	return nil
}
Пример #2
0
// If record exists with this key, nothing happens
func (connection *Connection) Create(primaryKey string, columns ColumnMap) (exists bool, err os.Error) {
	fmt.Printf("Create[%s]\n", primaryKey)
	cols := C.xtc_mapnew()
	defer C.xtc_mapdel(cols)
	for name, value := range columns {
		C.xtc_mapput(cols, C.CString(name), C.CString(value))
	}
	if C.xtcrdb_tblputkeep(connection.Tyrant, C.CString(primaryKey), cols) == 0 {
		if connection.ErrorCode() != ErrCodeKeep() {
			return exists, os.NewError(connection.ErrorMessage())
		}
		exists = true
	}
	return exists, nil
}