Coder Social home page Coder Social logo

dburl's Introduction

About dburl

Package dburl provides a standardized way of processing database connection strings for PostgreSQL, MySQL, SQLite, Oracle, and Microsoft SQL Server databases in the form of a URL.

Standard URLs are of the form protocol+transport://user:pass@host/dbname?opt1=a&opt2=b.

For example, the following are URLs that can be processed using Parse or Open:

    postgres://user:pass@localhost/mydb
    pgsql://user:[email protected]/anotherdb?sslmode=disable
    mysql://user:pass@localhost:8899/mydb
    oracle://user:[email protected]/someOtherDatabase
    mssql://localhost/databaseName
    sqlserver://localhost/databaseName
    sqlite://path/to/mydatabase.sqlite3
    file://mydb.sqlite3

Additional protocol aliases are provided for all of the databases in order to facilitate better handling of URLs from various sources.

Please note that you still need to import the related database driver package into your code.

Installation

Install in the usual Go fashion:

go install -u github.com/knq/dburl

Usage

Please see the GoDoc API page for a full API listing.

The dburl package can be used similarly to the following:

// example/example.go
package main

import (
	"fmt"
	"log"

	_ "github.com/denisenkom/go-mssqldb"
	"github.com/knq/dburl"
)

func main() {
	db, err := dburl.Open("sqlserver://user:pass@localhost/dbname")
	if err != nil {
		log.Fatal(err)
	}

	var name string
	err = db.QueryRow(`SELECT name FROM mytable WHERE id=10`).Scan(&name)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(">> got: %s\n", name)
}

Related Projects

  • xo - a command line tool to generate Go types from a database schema
  • usql - a universal/utility command line tool to execute queries on databases

dburl's People

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.