Exemplo n.º 1
0
func PlanetViewTableCreate(d db.DBer) error {
	query := `create table planetview(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	locx int NOT NULL,
	locy int NOT NULL,
	name varchar(20) NOT NULL,
	turn int NOT NULL,
	primaryfaction int REFERENCES faction ON DELETE SET NULL,
	primarypresence int NOT NULL,
	primarypower int NOT NULL,
	secondaryfaction int REFERENCES faction ON DELETE SET NULL,
	secondarypresence int NOT NULL,
	secondarypower int NOT NULL,
	antimatter int NOT NULL,
	tachyons int NOT NULL,
	FOREIGN KEY(gid, locx, locy) REFERENCES planet ON DELETE CASCADE,
	PRIMARY KEY(gid, fid, locx, locy)
);`
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed PlanetView table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 2
0
func TruceTableDelete(d db.DBer) error {
	query := "DROP TABLE IF EXISTS truce CASCADE"
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed Truce table deletion", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 3
0
func ShipViewTableDelete(d db.DBer) error {
	query := "DROP TABLE IF EXISTS shipview CASCADE"
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed ShipView table deletion", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 4
0
func LaunchRecordTableDelete(d db.DBer) error {
	query := "DROP TABLE IF EXISTS launchrecord CASCADE"
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed LaunchRecord table deletion", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 5
0
func PowerOrderTableDelete(d db.DBer) error {
	query := "DROP TABLE IF EXISTS powerorder CASCADE"
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed PowerOrder table deletion", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 6
0
func MapViewTableCreate(d db.DBer) error {
	query := `create table mapview(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	center point NOT NULL,
	PRIMARY KEY (gid, fid)
);`

	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed MapView table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 7
0
func TruceTableCreate(d db.DBer) error {
	query := `create table truce(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	locx int NOT NULL,
	locy int NOT NULL,
	trucee int NOT NULL REFERENCES faction ON DELETE CASCADE,
	FOREIGN KEY(gid, locx, locy) REFERENCES planet ON DELETE CASCADE,
	PRIMARY KEY(gid, fid, locx, locy, trucee)
);`
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed Truce table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 8
0
func ShipTableCreate(d db.DBer) error {
	query := `create table ship(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid int NOT NULL REFERENCES faction ON DELETE CASCADE,
	sid int NOT NULL,
	size int NOT NULL,
	launched int NOT NULL,
	path point[] NOT NULL,
	PRIMARY KEY(gid, fid, sid)
);`

	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed Ship table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 9
0
func PowerOrderTableCreate(d db.DBer) error {
	query := `create table powerorder(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	locx int NOT NULL,
	locy int NOT NULL,
	uppower int NOT NULL,
	FOREIGN KEY(gid, locx, locy) REFERENCES planet ON DELETE CASCADE,
	PRIMARY KEY(gid, fid)
);`

	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed PowerOrder table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 10
0
func Delete(d db.DBer, group DeleteGrouper) error {
	sqlers := group.DeleteList()
	if len(sqlers) == 0 {
		return nil
	}
	table := group.SQLTable()
	pkCols := group.PKCols()
	query, _ := sq.DELETE(table).WHERE(WherePK(pkCols)).Compile()
	argList := make([][]interface{}, len(sqlers))
	var err error
	for i, item := range sqlers {
		argList[i], err = ColVals(item, pkCols)
		if my, bad := Check(err, "delete failure on Colvals pkcols", "pkCols", pkCols, "index", i); bad {
			return my
		}
	}
	return db.Exec(d, true, query, argList...)
}
Exemplo n.º 11
0
func ShipViewTableCreate(d db.DBer) error {
	query := `create table shipview(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	controller integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	sid integer NOT NULL,
	turn integer NOT NULL,
	loc point,
	dest point,
	trail point[] NOT NULL,
	size int NOT NULL,
	PRIMARY KEY(gid, fid, turn, sid)
);`
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed ShipView table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 12
0
func GameTableCreate(d db.DBer) error {
	query := `create table game(
	gid SERIAL PRIMARY KEY,
	owner varchar(20) NOT NULL UNIQUE,
	name varchar(20) NOT NULL,
	turn int NOT NULL DEFAULT 0,
	autoturn int NOT NULL DEFAULT 0,
	freeautos int NOT NULL DEFAULT 0,
	towin int NOT NULL,
	highscore int NOT NULL DEFAULT 0,
	winner text DEFAULT NULL,
	password varchar(20) DEFAULT NULL
);`
	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed Game table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 13
0
func LaunchOrderTableCreate(d db.DBer) error {
	query := `create table launchorder(
	gid integer NOT NULL REFERENCES game ON DELETE CASCADE,
	fid integer NOT NULL REFERENCES faction ON DELETE CASCADE,
	sourcex integer NOT NULL,
	sourcey integer NOT NULL,
	targetx integer NOT NULL,
	targety integer NOT NULL,
	size integer NOT NULL,
	FOREIGN KEY(gid, sourcex, sourcey) REFERENCES planet ON DELETE CASCADE,
	FOREIGN KEY(gid, targetx, targety) REFERENCES planet ON DELETE CASCADE,
	PRIMARY KEY(gid, fid, sourcex, sourcey, targetx, targety)
);`

	err := db.Exec(d, false, query)
	if my, bad := Check(err, "failed LaunchOrder table creation", "query", query); bad {
		return my
	}
	return nil
}
Exemplo n.º 14
0
func Insert(d db.DBer, group InsertGrouper) error {
	sqlers := group.InsertList()
	if len(sqlers) == 0 {
		return nil
	}
	table := group.SQLTable()
	iCols := group.InsertCols()
	sCols := group.InsertScanCols()
	builder := sq.INSERT(table).COLS(iCols...)
	willScan := len(sCols) > 0
	if willScan {
		builder = builder.RETURN(sCols...)
	}
	query, _ := builder.Compile()
	qArgsList := make([][]interface{}, len(sqlers))
	var scanArgsList [][]interface{}
	if willScan {
		scanArgsList = make([][]interface{}, len(sqlers))
	}
	var err error
	for i, item := range sqlers {
		qArgsList[i], err = ColVals(item, iCols)
		if my, bad := Check(err, "insert failure on ColVals qArgs", "iCols", iCols, "index", i); bad {
			return my
		}
		if willScan {
			scanArgsList[i], err = ColPtrs(item, sCols)
			if my, bad := Check(err, "insert failure on ColPtrs sArgs", "sCols", sCols, "index", i); bad {
				return my
			}
		}
	}
	if willScan {
		return db.QueryRow(d, query, qArgsList, scanArgsList)
	} else {
		return db.Exec(d, true, query, qArgsList...)
	}
}
Exemplo n.º 15
0
func Update(d db.DBer, group UpdateGrouper) error {
	sqlers := group.UpdateList()
	if len(sqlers) == 0 {
		return nil
	}
	table := group.SQLTable()
	cols := group.UpdateCols()
	pkCols := group.PKCols()
	builder := sq.UPDATE(table).COLS(cols...).WHERE(WherePK(pkCols))
	query, _ := builder.Compile()
	qArgsList := make([][]interface{}, len(sqlers))
	for i, item := range sqlers {
		list, err := ColVals(item, cols)
		if my, bad := Check(err, "group update fail on update ColVals for item", "index", i, "item", item, "cols", cols); bad {
			return my
		}
		pkList, err := ColVals(item, pkCols)
		if my, bad := Check(err, "group update fail on pk ColVals for item", "index", i, "item", item, "pkCols", pkCols); bad {
			return my
		}
		qArgsList[i] = append(list, pkList...)
	}
	return db.Exec(d, true, query, qArgsList...)
}
Exemplo n.º 16
0
func DeleteWhere(d db.DBer, table string, where sq.Condition) error {
	query, args := sq.DELETE(table).WHERE(where).Compile()
	return db.Exec(d, false, query, args)
}