Skip to content

Commit 0304fc9

Browse files
Allow creating databases with dashes in the name (#125)
1 parent 0ab98b3 commit 0304fc9

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

prepare_database.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ func defaultCreateDatabase(port uint32, username, password, database string) (er
8282
err = connectionClose(db, err)
8383
}()
8484

85-
if _, err := db.Exec(fmt.Sprintf("CREATE DATABASE %s", database)); err != nil {
85+
if _, err := db.Exec(fmt.Sprintf("CREATE DATABASE \"%s\"", database)); err != nil {
8686
return errorCustomDatabase(database, err)
8787
}
8888

prepare_database_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ func Test_defaultCreateDatabase_ErrorWhenSQLOpenError(t *testing.T) {
116116
assert.EqualError(t, err, "unable to connect to create database with custom name database with the following error: client_encoding must be absent or 'UTF8'")
117117
}
118118

119+
func Test_defaultCreateDatabase_DashesInName(t *testing.T) {
120+
database := NewDatabase(DefaultConfig().
121+
Port(9832).
122+
Database("my-cool-database"))
123+
124+
if err := database.Start(); err != nil {
125+
t.Fatal(err)
126+
}
127+
128+
if err := database.Stop(); err != nil {
129+
t.Fatal(err)
130+
}
131+
}
132+
119133
func Test_defaultCreateDatabase_ErrorWhenQueryError(t *testing.T) {
120134
database := NewDatabase(DefaultConfig().
121135
Port(9831).

0 commit comments

Comments
 (0)