Example #1
0
func (s *PlanetSession) SelectByLocs(gid int, locations ...hexagon.Coord) ([]overpower.PlanetDat, error) {
	coordWhere := make([]sq.Condition, len(locations))
	for i, loc := range locations {
		coordWhere[i] = sq.AND(sq.EQ("locx", loc[0]), sq.EQ("locy", loc[1]))
	}
	where := sq.AND(sq.EQ("gid", gid), sq.OR(coordWhere...))
	return s.SelectWhere(where)
}
Example #2
0
func NewSource(m *Manager, gid int) *Source {
	return &Source{
		GID:        gid,
		M:          m,
		Where:      sq.EQ("gid", gid),
		updatedPVs: map[[3]int]int{},
	}
}
Example #3
0
func Delete(db DBer, table string, pkCols []string, items ...SQLer) error {
	itemLen := len(items)
	if itemLen == 0 {
		return nil
	}
	var query string
	if len(pkCols) == 1 {
		query, _ = sq.DELETE(table).WHERE(sq.EQ(pkCols[0], nil)).Compile()
	} else {
		conds := make([]sq.Condition, len(pkCols))
		for i, pk := range pkCols {
			conds[i] = sq.EQ(pk, nil)
		}
		query, _ = sq.DELETE(table).WHERE(sq.AND(conds...)).Compile()
	}
	stmt, err := db.Prepare(query)
	if my, bad := Check(err, "delete prepare failure", "query", query); bad {
		return my
	}
	defer stmt.Close()
	for i, item := range items {
		args, err := ColVals(item, pkCols)
		if my, bad := Check(err, "delete colvals failure", "index", i, "query", query, "pkCols", pkCols); bad {
			return my
		}
		res, err := stmt.Exec(args...)
		if my, bad := Check(err, "delete exec failure", "index", i, "query", query, "args", args); bad {
			return my
		}
		aff, err := res.RowsAffected()
		if my, bad := Check(err, "delete rows affected failure", "index", i, "query", query, "args", args); bad {
			return my
		}
		if aff != 1 {
			my, _ := Check(fmt.Errorf("inadequate rows affected %v", aff), "delete rows affected failure", "index", i, "query", query, "args", args, "affected", aff)
			return my
		}
	}
	return nil
}
Example #4
0
func (s *LaunchOrderSession) SelectBySource(gid, fid int, source hexagon.Coord) ([]overpower.LaunchOrderDat, error) {
	where := sq.AND(sq.EQ("gid", gid), sq.EQ("fid", fid),
		sq.AND(sq.EQ("sourcex", source[0]), sq.EQ("sourcey", source[1])),
	)
	return s.SelectWhere(where)
}
Example #5
0
func (m *Manager) TURN(gid, fid, turn int) sq.Condition {
	return sq.AND(sq.EQ("gid", gid), sq.EQ("fid", fid), sq.EQ("turn", turn))
}
Example #6
0
func (m *Manager) FID(gid, fid int) sq.Condition {
	return sq.AND(sq.EQ("gid", gid), sq.EQ("fid", fid))
}
Example #7
0
func (m *Manager) GID(gid int) sq.Condition {
	return sq.EQ("gid", gid)
}