Exemplo n.º 1
0
func New(driver, driverOptions string) (*Backend, apperror.Error) {
	b := &Backend{}
	b.BaseBackend = db.NewBaseBackend(b)
	b.SetName("sql")

	switch driver {
	case "postgres":
		b.dialect = NewPostgresDialect(b)
	case "mysql":
		b.dialect = &MysqlDialect{}
	case "sqlite3":
		b.dialect = &SqliteDialect{}
	default:
		panic("Unsupported sql driver: " + driver)
	}

	DB, err := sql.Open(driver, driverOptions)
	if err != nil {
		return nil, apperror.Wrap(err, "sql_connection_error")
	}

	b.Db = DB

	b.migrationHandler = db.NewMigrationHandler(b)
	b.RegisterModel(&MigrationAttempt{})

	b.BuildLogger()

	return b, nil
}
Exemplo n.º 2
0
func New() *Backend {
	b := &Backend{}
	b.BaseBackend = db.NewBaseBackend(b)
	b.SetName("memory")

	b.data = make(map[string]map[string]interface{})

	b.MigrationHandler = db.NewMigrationHandler(b)
	b.MigrationVersion = 0
	b.RegisterModel(&MigrationAttempt{})

	b.BuildLogger()

	return b
}