about summary refs log tree commit diff
path: root/src/bit.go
blob: 33c693ac8e842a0659f6b0f80f2c8acafa2b839c (plain)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package main

// struct element names can't start with nums...
type Bit struct {
	ID      int
	Name    string
	Enabled bool
}

//////////////////////////////////////////////////////////////////////////////
// GENERAL PURPOSE

func BitGetAll() ([]Bit, error) {
	return globalState.GetAllBits()
}

//////////////////////////////////////////////////////////////////////////////
// DATABASE

func (s *State) GetAllBits() ([]Bit, error) {
	rows, err := s.db.Query("SELECT id, name FROM bits")
	defer rows.Close()
	if err != nil {
		return nil, err
	}

	var bit []Bit
	for rows.Next() {
		var arch Bit
		if err := rows.Scan(&arch.ID, &arch.Name); err != nil {
			return bit, err
		}
		bit = append(bit, arch)
	}
	if err = rows.Err(); err != nil {
		return bit, err
	}
	return bit, nil
}

//////////////////////////////////////////////////////////////////////////////
// HTTP