Example #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"))
}
Example #2
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})
}