Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Use UNLOGGED TABLES on PostgreSQL #14

Merged
merged 4 commits into from
Apr 27, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions backends/sqldb.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,9 @@ func (s *sqlDB) createTableSchema(cols []string, colTypes []*sql.ColumnType) ins
}

var (
fields = make([]string, len(cols))
typ = ""
fields = make([]string, len(cols))
typ = ""
unlogged = ""
)
for i := 0; i < len(cols); i++ {
typ = colTypes[i].DatabaseTypeName()
Expand Down Expand Up @@ -277,9 +278,12 @@ func (s *sqlDB) createTableSchema(cols []string, colTypes []*sql.ColumnType) ins
fields[i] = fmt.Sprintf(`"%s" %s`, cols[i], typ)
}

if s.dbType == dbTypePostgres {
unlogged = "UNLOGGED "
}
return insertSchema{
dropTable: `DROP TABLE IF EXISTS "%s";`,
createTable: fmt.Sprintf(`CREATE TABLE IF NOT EXISTS "%%s" (%s);`, strings.Join(fields, ",")),
createTable: fmt.Sprintf(`CREATE %sTABLE IF NOT EXISTS "%%s" (%s);`, unlogged, strings.Join(fields, ",")),
fabriziomello marked this conversation as resolved.
Show resolved Hide resolved
insertRow: fmt.Sprintf(`INSERT INTO "%%s" (%s) VALUES (%s)`, strings.Join(colNameHolder, ","),
strings.Join(colValHolder, ",")),
}
Expand Down