diff --git a/dburl.go b/dburl.go index 211dd56..7983009 100644 --- a/dburl.go +++ b/dburl.go @@ -1,8 +1,8 @@ -// Package dburl provides a standard, URL style mechanism for parsing and -// opening SQL database connection strings for Go. Provides standardized way to -// parse and open URLs for popular databases PostgreSQL, MySQL, SQLite3, Oracle -// Database, Microsoft SQL Server, in addition to most other SQL databases with -// a publicly available Go driver. +// Package dburl provides a standard, [net/url.URL] style mechanism for parsing +// and opening SQL database connection strings for Go. Provides standardized +// way to parse and open [URL]'s for popular databases PostgreSQL, MySQL, SQLite3, +// Oracle Database, Microsoft SQL Server, in addition to most other SQL +// databases with a publicly available Go driver. // // See the [package documentation README section] for more details. // @@ -15,10 +15,11 @@ import ( "strings" ) -// Open takes a URL like "protocol+transport://user:pass@host/dbname?option1=a&option2=b" -// and opens a standard sql.DB connection. +// Open takes a URL string, also known as a DSN, in the form of +// "protocol+transport://user:pass@host/dbname?option1=a&option2=b" and opens a +// standard [sql.DB] connection. // -// See [Parse] for information on formatting URLs to work properly with Open. +// See [Parse] for information on formatting URL strings to work properly with Open. func Open(urlstr string) (*sql.DB, error) { u, err := Parse(urlstr) if err != nil { @@ -34,7 +35,7 @@ func Open(urlstr string) (*sql.DB, error) { // URL wraps the standard [net/url.URL] type, adding OriginalScheme, Transport, // Driver, Unaliased, and DSN strings. type URL struct { - // URL is the base net/url/URL. + // URL is the base [net/url.URL]. url.URL // OriginalScheme is the original parsed scheme (ie, "sq", "mysql+unix", "sap", etc). OriginalScheme string @@ -42,26 +43,26 @@ type URL struct { // "unix", ...), if provided. Transport string // Driver is the non-aliased SQL driver name that should be used in a call - // to sql/Open. + // to [sql.Open]. Driver string // GoDriver is the Go SQL driver name to use when opening a connection to - // the database. Used by Microsoft SQL Server's azuresql URLs, as the + // the database. Used by Microsoft SQL Server's azuresql:// URLs, as the // wire-compatible alias style uses a different syntax style. GoDriver string // UnaliasedDriver is the unaliased driver name. UnaliasedDriver string // DSN is the built connection "data source name" that can be used in a - // call to sql/Open. + // call to [sql.Open]. DSN string // hostPortDB will be set by Gen*() funcs after determining the host, port, // database. // - // when empty, indicates that these values are not special, and can be + // When empty, indicates that these values are not special, and can be // retrieved as the host, port, and path[1:] as usual. hostPortDB []string } -// Parse parses a URL, similar to the standard [net/url.Parse]. +// Parse parses a URL string, similar to the standard [net/url.Parse]. // // Handles parsing OriginalScheme, Transport, Driver, Unaliased, and DSN // fields. diff --git a/dburl_test.go b/dburl_test.go index 4a9b6a4..1bd0117 100644 --- a/dburl_test.go +++ b/dburl_test.go @@ -208,6 +208,8 @@ func TestParse(t *testing.T) { {`bend://user:pass@localhost/instance_name?sslmode=disabled&warehouse=wh`, `databend`, `bend://user:pass@localhost/instance_name?sslmode=disabled&warehouse=wh`, ``}, {`databend://user:pass@localhost/instance_name?tenant=tn&warehouse=wh`, `databend`, `databend://user:pass@localhost/instance_name?tenant=tn&warehouse=wh`, ``}, {`flightsql://user:pass@localhost?timeout=3s&token=foobar&tls=enabled`, `flightsql`, `flightsql://user:pass@localhost?timeout=3s&token=foobar&tls=enabled`, ``}, + {`duckdb:/path/to/foo.db?access_mode=read_only&threads=4`, `duckdb`, `/path/to/foo.db?access_mode=read_only&threads=4`, ``}, + {`dk:///path/to/foo.db?access_mode=read_only&threads=4`, `duckdb`, `/path/to/foo.db?access_mode=read_only&threads=4`, ``}, } for i, test := range tests { u, err := Parse(test.s) diff --git a/dsn.go b/dsn.go index 9bb0ca2..a106fff 100644 --- a/dsn.go +++ b/dsn.go @@ -13,14 +13,14 @@ import ( // Stat is the default stat func. // -// Used within the package to stat files, which is used when generating the -// DSNs for postgres, mysql, and sqlite3 URL schemes. +// Used internally to stat files, and is subsequently used when generating the +// DSNs for postgres://, mysql://, and sqlite3:// [URL] schemes. var Stat = func(name string) (fs.FileInfo, error) { return fs.Stat(os.DirFS(filepath.Dir(name)), filepath.Base(name)) } -// GenScheme returns a func that generates a scheme:// style DSN from the -// passed URL. +// GenScheme returns a generator that will generate a scheme based on the +// passed scheme DSN. func GenScheme(scheme string) func(*URL) (string, string, error) { return func(u *URL) (string, string, error) { z := &url.URL{ diff --git a/scheme.go b/scheme.go index 3f0c985..1702048 100644 --- a/scheme.go +++ b/scheme.go @@ -163,6 +163,12 @@ func BaseSchemes() []Scheme { []string{"ch"}, "", }, + { + "duckdb", + GenOpaque, 0, true, + []string{"dk", "ddb", "duck"}, + "", + }, { "cosmos", GenCosmos, 0, false,