コード例 #1
0
ファイル: query_builder.go プロジェクト: dfalgout/cdd
func main() {
	flag.Parse()
	db := DBConnect("root:" + *password + "@tcp(localhost:3306)/")

	opts := libs.Options{DropSchema: true}

	var fields []schemas.Field

	for i := 1; i < 5; i++ {
		fields = append(fields, schemas.Field{Name: "testField_" + strconv.Itoa(i), Type: "string"})
	}

	table := schemas.Table{Name: "Table_One", Fields: fields}
	builder := libs.NewBuilder(opts)
	builder.CreateSchema("test")
	builder.UseSchema("test")
	builder.CreateTable(table)
	query := builder.Build()
	fmt.Println("builder.BUILD()")
	fmt.Println(query)
	fmt.Println("END builder.BUILD()")

	err := builder.Commit(db)
	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Success!")
	}
}
コード例 #2
0
ファイル: main.go プロジェクト: dfalgout/cdd
func createSchema(res http.ResponseWriter, req *http.Request) {

	res.Header().Set("Content-Type", "application/json")

	var schema schemas.Schema

	decoder := json.NewDecoder(req.Body)
	err := decoder.Decode(&schema)
	okOrDie(err)

	opts := libs.Options{DropSchema: true, DropTable: true}

	builder := libs.NewBuilder(opts)

	builder.CreateSchema(schema.Name).UseSchema(schema.Name)
	for _, i := range schema.Tables {
		builder.CreateTable(i)
	}

	fmt.Println(builder.Build())

	err = builder.Commit(db)
	okOrDie(err)

	//migration.InitRedis(":6379", "password")
	//migration.SaveSchema(schema)

	//err = schema.GenerateSchema(db)
	//okOrDie(err)

	res.Write(prettyPrint(schema))
}