feat: add spec definition api with versioning
This commit is contained in:
@ -104,3 +104,40 @@ func NewTenantRepository(ctx context.Context, conf config.DatabaseConfig) (datas
|
||||
|
||||
return tenantRepository, nil
|
||||
}
|
||||
|
||||
func NewSpecDefinitionRepository(ctx context.Context, conf config.DatabaseConfig) (datastore.SpecDefinitionRepository, error) {
|
||||
driver := string(conf.Driver)
|
||||
dsn := string(conf.DSN)
|
||||
|
||||
var specDefRepository datastore.SpecDefinitionRepository
|
||||
|
||||
logger.Debug(ctx, "initializing spec definition repository", logger.F("driver", driver), logger.F("dsn", dsn))
|
||||
|
||||
switch driver {
|
||||
case config.DatabaseDriverPostgres:
|
||||
// TODO
|
||||
// pool, err := openPostgresPool(ctx, dsn)
|
||||
// if err != nil {
|
||||
// return nil, errors.WithStack(err)
|
||||
// }
|
||||
|
||||
// entryRepository = postgres.NewEntryRepository(pool)
|
||||
case config.DatabaseDriverSQLite:
|
||||
url, err := url.Parse(dsn)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
db, err := sql.Open(driver, url.Host+url.Path)
|
||||
if err != nil {
|
||||
return nil, errors.WithStack(err)
|
||||
}
|
||||
|
||||
specDefRepository = sqlite.NewSpecDefinitionRepository(db, 5)
|
||||
|
||||
default:
|
||||
return nil, errors.Errorf("unsupported database driver '%s'", driver)
|
||||
}
|
||||
|
||||
return specDefRepository, nil
|
||||
}
|
||||
|
Reference in New Issue
Block a user