https://github.com/recursionpharma/go-dbutil
Golang utilities for interacting with databases
https://github.com/recursionpharma/go-dbutil
Last synced: 5 months ago
JSON representation
Golang utilities for interacting with databases
- Host: GitHub
- URL: https://github.com/recursionpharma/go-dbutil
- Owner: recursionpharma
- License: mit
- Created: 2016-05-25T17:55:40.000Z (about 10 years ago)
- Default Branch: trunk
- Last Pushed: 2025-06-06T03:05:49.000Z (about 1 year ago)
- Last Synced: 2025-06-06T04:19:18.752Z (about 1 year ago)
- Language: Go
- Size: 13.7 KB
- Stars: 1
- Watchers: 73
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://infosec-docs.prod.rxrx.io/octoguard/scorecards/go-dbutil)
[](https://infosec-docs.prod.rxrx.io/octoguard/scorecards/go-dbutil)
# go-dbutil
Golang utilities for interacting with databases
## Install
go get github.com/recursionpharma/go-dbutil
## Usage
See also `examples_test.go`.
### Given a DB URL, connect to the DB
This is useful since `sql.Open()` requires you to pass the driver in addition to the URL,
even though the driver is embedded in the URL.
import (
"os"
"fmt"
"github.com/recursionpharma/go-dbutil"
)
func main() {
db, err := dbutil.Connect("postgres://USER:PASSWORD@HOST:PORT/DBNAME")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(db != nil)
// Output: true
}
### Extract the driver from a DB URL
import (
"os"
"fmt"
"github.com/recursionpharma/go-dbutil"
)
func main() {
driver, err := GetDriver("postgres://USER:PASSWORD@HOST:PORT/DBNAME")
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(driver)
// Output: postgres
}
## Directory Structure
```
code/go-dbutil/
|-- dbutil.go
| Code
|-- dbutil_test.go
| Tests
|-- examples_test.go
| Examples
|-- .gitignore
| Files git will ignore
|-- LICENSE
| MIT License
|-- README.md
| This file
`-- .travis.yml
Travis config
```
The above file tree was generated with `tree -a -L 1 --charset ascii`.