yats.git

ref: f79a9d09c451653ff27fb34afb5b0c71dc758a32

server/db/clients.go


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package db

import (
	"fmt"
	"time"
	"yats-server/model"

	"github.com/gocql/gocql"
)

func GetClientsList(session *gocql.Session) []model.ClientInfo {
	var clients []model.ClientInfo
	m := map[string]interface{}{}

	q := fmt.Sprintf("SELECT  id, created, name FROM client")
	fmt.Println(q)
	iter := session.Query(q).Iter()
	for iter.MapScan(m) {
		clients = append(clients, model.ClientInfo{
			ID:      m["id"].(string),
			Created: m["created"].(time.Time).UnixMilli(),
			Name:    m["name"].(string),
		})
		m = map[string]interface{}{}
	}
	return clients
}