Пример #1
0
func Example() {
	t1 := sb.NewTable(
		"parent_prefix",
		sb.IntColumn("ns_id", false),
		sb.IntColumn("hash", false),
		sb.StrColumn(
			"prefix",
			sb.UTF8,
			sb.UTF8CaseInsensitive,
			false))

	t2 := sb.NewTable(
		"sfj",
		sb.IntColumn("ns_id", false),
		sb.IntColumn("sjid", false),
		sb.StrColumn(
			"filename",
			sb.UTF8,
			sb.UTF8CaseInsensitive,
			false))

	ns_id1 := t1.C("ns_id")
	prefix := t1.C("prefix")
	ns_id2 := t2.C("ns_id")
	sjid := t2.C("sjid")
	filename := t2.C("filename")

	in := []int32{1, 2, 3}
	join := t2.LeftJoinOn(t1, sb.Eq(ns_id1, ns_id2))
	q := join.Select(ns_id2, sjid, prefix, filename).Where(
		sb.And(sb.EqL(ns_id2, 123), sb.In(sjid, in)))
	fmt.Println(q.String("shard1"))
}
Пример #2
0
func (r *logReader) newInsertStat(logid uint, tblName string) sqlbuilder.InsertStatement {
	cfg := r.logConfByID(logid)

	columns := make([]sqlbuilder.NonAliasColumn, len(cfg.Field_list))
	for i := 0; i < len(cfg.Field_list); i++ {
		field := &cfg.Field_list[i]
		if field.TypeInt == prod.FIELD_TYPE_INT {
			columns[i] = sqlbuilder.IntColumn(field.Column, true)
		} else if field.TypeInt == prod.FIELD_TYPE_UINT {
			columns[i] = sqlbuilder.IntColumn(field.Column, true)
		} else {
			columns[i] = sqlbuilder.BytesColumn(field.Column, true)
		}
	}
	table := sqlbuilder.NewTable(tblName, columns...)
	return table.Insert(columns...)
}
Пример #3
0
func getMessage(c *iris.Context) {
	t := sb.NewTable(
		"chats",
		sb.StrColumn("roomid", sb.UTF8, sb.UTF8CaseSensitive, false),
		sb.StrColumn("text", sb.UTF8, sb.UTF8CaseSensitive, false),
	)
	query, _ := t.Select(t.C("roomid"), t.C("text")).String("chat")
	rows, err := db.Query(query)
	if err != nil {
		log.Fatal(err)
	}
	var messages []string
	for rows.Next() {
		var roomid string
		var text string
		if err := rows.Scan(&roomid, &text); err != nil {
			log.Fatal(err)
		}
		messages = append(messages, text)
	}
	c.JSON(iris.StatusOK, map[string][]string{"messages": messages})
}