Skip to content

Commit da92587

Browse files
murfffikenshaw
authored andcommitted
Support duckdb empty path to specify in-memory DB
Closes #41
1 parent 2a98895 commit da92587

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

dburl_test.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func TestBadParse(t *testing.T) {
2424
{`file+tcp://`, ErrInvalidTransportProtocol},
2525
{`file://`, ErrMissingPath},
2626
{`ql://`, ErrMissingPath},
27-
{`duckdb://`, ErrMissingPath},
2827
{`mssql+tcp://user:pass@host/dbname`, ErrInvalidTransportProtocol},
2928
{`mssql+foobar://`, ErrInvalidTransportProtocol},
3029
{`mssql+unix:/var/run/mssql.sock`, ErrInvalidTransportProtocol},
@@ -787,6 +786,24 @@ func TestParse(t *testing.T) {
787786
`/path/to/foo.db?access_mode=read_only&threads=4`,
788787
``,
789788
},
789+
{
790+
`duckdb://`,
791+
`duckdb`,
792+
``,
793+
``,
794+
},
795+
{
796+
`duckdb://:memory:`,
797+
`duckdb`,
798+
`:memory:`,
799+
``,
800+
},
801+
{
802+
`duckdb:?threads=4`,
803+
`duckdb`,
804+
`?threads=4`,
805+
``,
806+
},
790807
{
791808
`file:./testdata/test.sqlite3?a=b`,
792809
`sqlite3`,

dsn.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,12 @@ func GenYDB(u *URL) (string, string, error) {
662662
return s + genOptions(u.Query(), "?", "=", "&", ",", true, nil, nil), "", nil
663663
}
664664

665+
// GenDuckDB generates a duckdb dsn from the passed URL.
666+
func GenDuckDB(u *URL) (string, string, error) {
667+
// Same as GenOpaque but accepts empty path which refers to in-memory DB
668+
return u.Opaque + genQueryOptions(u.Query()), "", nil
669+
}
670+
665671
// convertOptions converts an option value based on name, value pairs.
666672
func convertOptions(q url.Values, pairs ...string) url.Values {
667673
n := make(url.Values)

scheme.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func BaseSchemes() []Scheme {
202202
},
203203
{
204204
"duckdb",
205-
GenOpaque, 0, true,
205+
GenDuckDB, 0, true,
206206
[]string{"dk", "ddb", "duck"},
207207
"",
208208
},

0 commit comments

Comments
 (0)