Skip to content

Commit

Permalink
fix: conversion of sqlite to postgres syntax (#1569)
Browse files Browse the repository at this point in the history
  • Loading branch information
sven-urbanski-freiheit-com authored May 2, 2024
1 parent 1467368 commit d4aa190
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions services/cd-service/pkg/repository/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,15 @@ func RunDBMigrations(cfg DBConfig) error {

func (h *DBHandler) AdaptQuery(query string) string {
if h.DriverName == "postgres" {
return query
return SqliteToPostgresQuery(query)
} else if h.DriverName == "sqlite3" {
return PostgresToSqliteQuery(query)
return query
}
panic(fmt.Errorf("AdaptQuery: invalid driver: %s", h.DriverName))
}

// PostgresToSqliteQuery just replaces all "?" into "$1", "$2", etc
func PostgresToSqliteQuery(query string) string {
// SqliteToPostgresQuery just replaces all "?" into "$1", "$2", etc
func SqliteToPostgresQuery(query string) string {
var q = query
var i = 1
for strings.Contains(q, "?") {
Expand Down
4 changes: 2 additions & 2 deletions services/cd-service/pkg/repository/db_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ INSERT INTO all_apps (version , created , json) VALUES (1, '1713218400', '{"ap
}
}

func TestPostgresToSqliteQuery(t *testing.T) {
func TestSqliteToPostgresQuery(t *testing.T) {
tcs := []struct {
Name string
inputQuery string
Expand Down Expand Up @@ -166,7 +166,7 @@ func TestPostgresToSqliteQuery(t *testing.T) {
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()

actualQuery := PostgresToSqliteQuery(tc.inputQuery)
actualQuery := SqliteToPostgresQuery(tc.inputQuery)
if diff := cmp.Diff(tc.expectedQuery, actualQuery); diff != "" {
t.Errorf("response mismatch (-want, +got):\n%s", diff)
}
Expand Down

0 comments on commit d4aa190

Please sign in to comment.