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


Golang common.BufferWriter类代码示例

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


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

示例1: writeUint64

func writeUint64(buf common.BufferWriter, n uint64) {
	if n < maxLookup {
		buf.WriteString(itoaTab[int(n)])
	} else {
		buf.WriteString(strconv.FormatUint(n, 10))
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:7,代码来源:util.go

示例2: writeScopeCondition

// Invariant: for scope conditions only
func writeScopeCondition(buf common.BufferWriter, f *whereFragment, args *[]interface{}, pos *int64) {
	buf.WriteRune(' ')
	if len(f.Values) > 0 {
		// map relative $1, $2 placeholders to absolute
		replaced := remapPlaceholders(buf, f.Condition, *pos)
		*pos += replaced
		*args = append(*args, f.Values...)
	} else {
		buf.WriteString(f.Condition)
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:12,代码来源:where.go

示例3: writeWhereFragmentsToSql

// Invariant: only called when len(fragments) > 0
func writeWhereFragmentsToSql(buf common.BufferWriter, fragments []*whereFragment, args *[]interface{}, pos *int64) {
	hasConditions := false
	for _, f := range fragments {
		if f.Condition != "" {
			if hasConditions {
				buf.WriteString(" AND (")
			} else {
				buf.WriteRune('(')
				hasConditions = true
			}

			if len(f.Values) > 0 {
				// map relative $1, $2 placeholders to absolute
				replaced := remapPlaceholders(buf, f.Condition, *pos)
				*pos += replaced
				*args = append(*args, f.Values...)
			} else {
				buf.WriteString(f.Condition)
			}
			buf.WriteRune(')')
		} else if f.EqualityMap != nil {
			hasConditions = writeEqualityMapToSql(buf, f.EqualityMap, args, hasConditions, pos)
		} else {
			panic("invalid equality map")
		}
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:28,代码来源:where.go

示例4: WriteIdentifier

// WriteIdentifier writes escaped identifier.
func (pd *Postgres) WriteIdentifier(buf common.BufferWriter, ident string) {
	if ident == "" {
		panic("Identifier is empty string")
	}

	buf.WriteRune('"')
	if strings.Contains(ident, ".") {
		for _, char := range ident {
			if char == '.' {
				buf.WriteString("\".\"")
			} else {
				buf.WriteRune(char)
			}
		}
	} else {
		buf.WriteString(ident)
	}
	buf.WriteRune('"')
}
开发者ID:syreclabs,项目名称:dat,代码行数:20,代码来源:postgres.go

示例5: writeWhereCondition

func writeWhereCondition(buf common.BufferWriter, k string, pred string, anyConditions bool) bool {
	if anyConditions {
		buf.WriteString(" AND (")
	} else {
		buf.WriteRune('(')
		anyConditions = true
	}
	Dialect.WriteIdentifier(buf, k)
	buf.WriteString(pred)
	buf.WriteRune(')')

	return anyConditions
}
开发者ID:syreclabs,项目名称:dat,代码行数:13,代码来源:where.go

示例6: remapPlaceholders

func remapPlaceholders(buf common.BufferWriter, statement string, start int64) int64 {
	if !strings.Contains(statement, "$") {
		buf.WriteString(statement)
		return 0
	}

	highest := 0
	pos := int(start) - 1 // 0-based
	statement = rePlaceholder.ReplaceAllStringFunc(statement, func(s string) string {
		i, _ := strconv.Atoi(s[1:])
		if i > highest {
			highest = i
		}

		sum := strconv.Itoa(pos + i)
		return "$" + sum
	})

	buf.WriteString(statement)
	return int64(highest)
}
开发者ID:syreclabs,项目名称:dat,代码行数:21,代码来源:where.go

示例7: writeEqualityMapToSql

func writeEqualityMapToSql(buf common.BufferWriter, eq map[string]interface{}, args *[]interface{}, anyConditions bool, pos *int64) bool {
	for k, v := range eq {
		if v == nil {
			anyConditions = writeWhereCondition(buf, k, " IS NULL", anyConditions)
		} else {
			vVal := reflect.ValueOf(v)

			if vVal.Kind() == reflect.Array || vVal.Kind() == reflect.Slice {
				vValLen := vVal.Len()
				if vValLen == 0 {
					if vVal.IsNil() {
						anyConditions = writeWhereCondition(buf, k, " IS NULL", anyConditions)
					} else {
						if anyConditions {
							buf.WriteString(" AND (1=0)")
						} else {
							buf.WriteString("(1=0)")
						}
					}
				} else if vValLen == 1 {
					anyConditions = writeWhereCondition(buf, k, equalsPlaceholderTab[*pos], anyConditions)
					*args = append(*args, vVal.Index(0).Interface())
					*pos++
				} else {
					// " IN $n"
					anyConditions = writeWhereCondition(buf, k, inPlaceholderTab[*pos], anyConditions)
					*args = append(*args, v)
					*pos++
				}
			} else {
				anyConditions = writeWhereCondition(buf, k, equalsPlaceholderTab[*pos], anyConditions)
				*args = append(*args, v)
				*pos++
			}
		}
	}

	return anyConditions
}
开发者ID:syreclabs,项目名称:dat,代码行数:39,代码来源:where.go

示例8: writePlaceholder64

func writePlaceholder64(buf common.BufferWriter, pos int64) {
	if pos < maxLookup {
		buf.WriteString(placeholderTab[pos])
	} else {
		buf.WriteRune('$')
		buf.WriteString(strconv.FormatInt(pos, 10))
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:8,代码来源:util.go

示例9: writePlaceholder

func writePlaceholder(buf common.BufferWriter, pos int) {
	if pos < maxLookup {
		buf.WriteString(placeholderTab[pos])
	} else {
		buf.WriteRune('$')
		buf.WriteString(strconv.Itoa(pos))
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:8,代码来源:util.go

示例10: writeKVWhere

// writeKVWhere writes "col1" = $1 AND "col2" = $2, ... "coln" = $n
func writeKVWhere(buf common.BufferWriter, columns []string, values []interface{}, args *[]interface{}, anyConditions bool, pos *int64) bool {
	if len(columns) != len(values) {
		panic("Mismatch of column and values")
	}

	for i, k := range columns {
		v := values[i]

		if v == nil {
			anyConditions = writeWhereCondition(buf, k, " IS NULL", anyConditions)
		} else if e, ok := v.(*Expression); ok {
			start := pos
			buf.WriteString(" = ")
			// map relative $1, $2 placeholders to absolute
			remapPlaceholders(buf, e.Sql, *start)
			*args = append(*args, e.Args...)
			*pos += int64(len(e.Args))
		} else {
			vVal := reflect.ValueOf(v)

			if vVal.Kind() == reflect.Array || vVal.Kind() == reflect.Slice {
				vValLen := vVal.Len()
				if vValLen == 0 {
					if vVal.IsNil() {
						anyConditions = writeWhereCondition(buf, k, " IS NULL", anyConditions)
					} else {
						if anyConditions {
							buf.WriteString(" AND (1=0)")
						} else {
							buf.WriteString("(1=0)")
						}
					}
				} else if vValLen == 1 {
					anyConditions = writeWhereCondition(buf, k, equalsPlaceholderTab[*pos], anyConditions)
					*args = append(*args, vVal.Index(0).Interface())
					*pos++
				} else {
					// " IN $n"
					anyConditions = writeWhereCondition(buf, k, inPlaceholderTab[*pos], anyConditions)
					*args = append(*args, v)
					*pos++
				}
			} else {
				anyConditions = writeWhereCondition(buf, k, equalsPlaceholderTab[*pos], anyConditions)
				*args = append(*args, v)
				*pos++
			}
		}
	}

	return anyConditions
}
开发者ID:syreclabs,项目名称:dat,代码行数:53,代码来源:list_helpers.go

示例11: WriteStringLiteral

// WriteStringLiteral writes an escaped string. No escape characters
// are allowed.
//
// Postgres 9.1+ does not allow any escape
// sequences by default. See http://www.postgresql.org/docs/9.3/interactive/sql-syntax-lexical.html#SQL-SYNTAX-STRINGS-ESCAPE
// In short, all backslashes are treated literally not as escape sequences.
func (pd *Postgres) WriteStringLiteral(buf common.BufferWriter, val string) {
	if val == "" {
		buf.WriteString("''")
		return
	}

	hasTag := true

	// don't use double dollar quote strings unless the string is long enough
	if len(val) > 64 {
		// if pgDollarTag unique tag is in string, try to create a new one (only once though)
		hasTag = strings.Contains(val, pgDollarTag)
		if hasTag {
			randomizePgDollarTag()
			hasTag = strings.Contains(val, pgDollarTag)
		}
	}

	if hasTag {
		buf.WriteRune('\'')
		if strings.Contains(val, "'") {
			for _, char := range val {
				// apos
				if char == '\'' {
					buf.WriteString(`''`)
				} else if char == 0 {
					panic("postgres doesn't support NULL char in text, see http://stackoverflow.com/questions/1347646/postgres-error-on-insert-error-invalid-byte-sequence-for-encoding-utf8-0x0")
				} else {
					buf.WriteRune(char)
				}
			}
		} else {
			buf.WriteString(val)
		}
		buf.WriteRune('\'')
	} else {
		buf.WriteString(pgDollarTag)
		buf.WriteString(val)
		buf.WriteString(pgDollarTag)
	}
}
开发者ID:syreclabs,项目名称:dat,代码行数:47,代码来源:postgres.go


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