gosora/query_gen/lib/install.go
Azareal fdb6304e32 Mostly a mid-way technical commit to make reading diffs easier on me.
Split the relativeTime function into relativeTime and relativeTimeFromString.
Refactored the installer.
Made a lot of progress with PgSQL and MSSQL support, mostly MSSQL.
Made a lot of progress on the automated testing suite.
Added eqcss to the file extension list.
..depressed..
Fixed various bugs here and there.
gen_mysql.go is now properly excluded when the pgsql or mssql build tag is passed.
The BBCode plugin is now always initialised prior to it's test.
We've begun transitioning towards deserializing database times directly into time.Times rather than doing it every time on the spot.
Added more dev flags.
The tests now make use of a test database rather than the production database.
2017-10-14 08:39:22 +01:00

71 lines
2.1 KiB
Go

/* WIP Under Construction */
package qgen
var Install *installer
func init() {
Install = &installer{instructions: []DB_Install_Instruction{}}
}
type DB_Install_Instruction struct {
Table string
Contents string
Type string
}
// A set of wrappers around the generator methods, so we can use this in the installer
// TODO: Re-implement the query generation, query builder and installer adapters as layers on-top of a query text adapter
type installer struct {
adapter DB_Adapter
instructions []DB_Install_Instruction
}
func (install *installer) SetAdapter(name string) error {
adap, err := GetAdapter(name)
if err != nil {
return err
}
install.adapter = adap
install.instructions = []DB_Install_Instruction{}
return nil
}
func (install *installer) SetAdapterInstance(adapter DB_Adapter) {
install.adapter = adapter
install.instructions = []DB_Install_Instruction{}
}
func (install *installer) CreateTable(table string, charset string, collation string, columns []DB_Table_Column, keys []DB_Table_Key) error {
res, err := install.adapter.CreateTable("_installer", table, charset, collation, columns, keys)
if err != nil {
return err
}
install.instructions = append(install.instructions, DB_Install_Instruction{table, res, "create-table"})
return nil
}
func (install *installer) SimpleInsert(table string, columns string, fields string) error {
res, err := install.adapter.SimpleInsert("_installer", table, columns, fields)
if err != nil {
return err
}
install.instructions = append(install.instructions, DB_Install_Instruction{table, res, "insert"})
return nil
}
func (install *installer) Write() error {
var inserts string
// We can't escape backticks, so we have to dump it out a file at a time
for _, instr := range install.instructions {
if instr.Type == "create-table" {
err := writeFile("./schema/"+install.adapter.GetName()+"/query_"+instr.Table+".sql", instr.Contents)
if err != nil {
return err
}
} else {
inserts += instr.Contents + ";\n"
}
}
return writeFile("./schema/"+install.adapter.GetName()+"/inserts.sql", inserts)
}