Esempio n. 1
0
func initSchema() {
	dbm, err := db.Create(
		&db.Setting{
			URL: os.Getenv("DATABASE_URL"),
		},
	)
	if err != nil {
		panic(err)
	}
	defer dbm.CloseDB()
	dbm.DropTableWithCascade(&RawData{})
	dbm.AutoMigrate(&RawData{})
}
Esempio n. 2
0
func Create(setting *Setting) (*BridgeDB, error) {
	var err error
	dbm, err := db.Create(setting.DB)
	if err != nil {
		return nil, err
	}
	mc := mqtt.Create(setting.MQTT)
	return &BridgeDB{
		setting:    setting,
		mqttClient: mc,
		dbm:        dbm,
		wg:         sync.WaitGroup{},
		counter:    int64(0),
	}, nil
}