Пример #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
}
Пример #2
0
func New(host, database, user, password string) (*Backend, apperror.Error) {
	b := &Backend{}
	b.BaseBackend = db.NewBaseBackend(b)
	b.SetName("orientdb")

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

	b.BuildLogger()

	// Connect to orient.
	client, err := orient.Dial(host)
	if err != nil {
		return nil, apperror.Wrap(err, "orient_dial_error")
	}
	db, err := client.Open(database, orient.DocumentDB, user, password)
	if err != nil {
		return nil, apperror.Wrap(err, "orient_db_open_error")
	}
	b.Db = db

	b.translator = NewTranslator(b)

	return b, nil
}
Пример #3
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
}