1. Relational Databases
1.1 MySQL
https://github.com/go-sql-driver/mysql/
1
2
3
4
5
6
7
8
9
10
11
12
|
[username[:password]@][protocol[(address)]]/dbname[?param1=value1&...¶mN=valueN]
// user@unix(/path/to/socket)/dbname
// root:pw@unix(/tmp/mysql.sock)/myDatabase?loc=Local
// user:password@tcp(localhost:5555)/dbname?tls=skip-verify&autocommit=true
// user:password@/dbname?sql_mode=TRADITIONAL
// user:password@tcp([de:ad:be:ef::ca:fe]:80)/dbname?timeout=90s&collation=utf8mb4_unicode_ci
// id:password@tcp(your-amazonaws-uri.com:3306)/dbname
// user@cloudsql(project-id:instance-name)/dbname
// user@cloudsql(project-id:regionname:instance-name)/dbname
// user:password@tcp/dbname?charset=utf8mb4,utf8&sys_var=esc%40ped
// user:password@/dbname
// user:password@/
|
1.2 Postgres (pure Go)
https://github.com/lib/pq
1
2
3
4
5
6
7
8
9
|
postgres://[user[:password]@][netloc][:port][,...][/dbname][?param1=value1&...]
postgres://
postgres://localhost
postgres://localhost:5433
postgres://localhost/mydb
postgres://user@localhost
postgres://user:secret@localhost
postgres://other@localhost/otherdb?connect_timeout=10&application_name=myapp
postgres://host1:123,host2:456/somedb?target_session_attrs=any&application_name=myapp
|
1.3 SQLite (uses cgo)
https://github.com/mattn/go-sqlite3
1
2
3
4
|
test.db
file:test.db?cache=shared&mode=memory
:memory:
file::memory:
|
More parameters can be found in SQLiteDriver.Open
1.4 Apache Ignite/GridGain
https://github.com/amsokol/ignite-go-client
1
|
protocol://host:port/cache?param1=value1¶m2=value2¶mN=valueN
|
For detailed settings of each section, please refer to How to use SQL driver.
1.5 Apache Avatica/Phoenix
https://github.com/apache/calcite-avatica-go
1
|
http://[username:password@]address:port[/schema][?parameter1=value&...parameterN=value]
|
1.6 AWS Athena
https://godoc.org/github.com/segmentio/go-athena#Driver.Open
1
|
db=default&output_location=s3://results
|
Optional values poll_frequency
and region
1.7 ClickHouse Via TCP
https://github.com/kshvakov/clickhouse#dsn
1
|
tcp://host1:9000?username=user&password=qwerty&database=clicks&read_timeout=10&write_timeout=20&alt_hosts=host2:9000,host3:9000
|
1.8 ClickHouse Via HTTP
https://github.com/mailru/go-clickhouse#dsn
1
|
schema://user:password@host[:port]/database?param1=value1&...¶mN=valueN
|
1.9 DB2
https://bitbucket.org/phiggins/db2cli
1
|
DATABASE=db; HOSTNAME=dbhost; PORT=40000; PROTOCOL=TCPIP; UID=me; PWD=secret;
|
1.10 DB2 LUW Via CGO
https://github.com/asifjalil/cli
1
2
3
|
sqlconnect;[DATABASE=<database_name>;][UID=<user_id>;][PWD=<password>;]
DSN=Sample; UID=asif; PWD=secrect; AUTOCOMMIT=0; CONNECTTYPE=1;
DATABASE=db; HOSTNAME=dbhost; PORT=40000; PROTOCOL=TCPIP; UID=me; PWD=secret;
|
1.11 Firebird SQL
https://github.com/nakagami/firebirdsql
1
|
user:password@servername[:port_number]/database_name_or_file[?params1=value1[¶m2=value2]...]
|
1.12 MS ADODB
https://github.com/mattn/go-adodb
1
2
|
DSN=myDsn;Uid=myUsername;Pwd=;
FILEDSN=c:\myDsnFile.dsn;Uid=myUsername;Pwd=;
|
1.13 MS SQL Server (pure go)
https://github.com/denisenkom/go-mssqldb#connection-parameters-and-dsn
1
|
qlserver://username:password@host/instance?param1=value¶m2=value
|
1.14 MS SQL Server (uses cgo)
https://github.com/minus5/gofreetds
1
|
Server=myServerAddress;Database=myDatabase;User Id=myUsername;Password=myPassword;Failover Partner=myMirror;Max Pool Size=200;Compatibility Mode=Sybase
|
1.15 MySQL by ziutek
https://github.com/ziutek/mymysql
1
2
3
4
5
6
|
[PROTOCOL_SPECIFIC*]DBNAME/USER/PASSWD
// DBNAME/USER/PASSWD
// unix:SOCKPATH*DBNAME/USER/PASSWD
// unix:SOCKPATH,OPTIONS*DBNAME/USER/PASSWD
// tcp:ADDR*DBNAME/USER/PASSWD
// tcp:ADDR,OPTIONS*DBNAME/USER/PASSWD
|
1.16 ODBC
https://bitbucket.org/miquella/mgodbc
1
2
|
DSN=myDsn;Uid=myUsername;Pwd=;
FILEDSN=c:\myDsnFile.dsn;Uid=myUsername;Pwd=;
|
1.17 ODBC
https://github.com/alexbrainman/odbc
1
2
|
DSN=myDsn;Uid=myUsername;Pwd=;
FILEDSN=c:\myDsnFile.dsn;Uid=myUsername;Pwd=;
|
1.18 Oracle
https://github.com/mattn/go-oci8
1
|
[username/[password]@]host[:port][/instance_name][?param1=value1&...¶mN=valueN]
|
1.19 Oracle
https://gopkg.in/rana/ora.v4
1
|
username/password@dblink
|
1.20 Oracle
https://gopkg.in/goracle.v2
1
2
3
4
5
6
7
8
9
10
11
|
ora://login:password@sid/? \
sysdba=0& \
sysoper=0& \
poolMinSessions=1& \
poolMaxSessions=1000& \
poolIncrement=1& \
connectionClass=POOLED& \
standaloneConnection=0& \
enableEvents=0& \
heterogeneousPool=0& \
prelim=0
|
1.21 QL
http://godoc.org/github.com/cznic/ql/driver
1
2
3
|
ql.db
file://ql.db
memory://mem.db
|
1.22 Postgres (pure Go)
https://github.com/jackc/pgx
1
2
|
user=username password=password host=1.2.3.4 port=5432 dbname=mydb sslmode=disable
application_name=pgxtest search_path=admin user=username password=password host=1.2.3.4 dbname=mydb
|
1.23 Presto
https://github.com/prestodb/presto-go-client
1
|
http[s]://user[:pass]@host[:port][?parameters]
|
1.24 SAP HANA (pure go)
https://github.com/SAP/go-hdb
1
2
3
4
|
hdb://<username>:<password>@<host address>:<port number>
// "hdb://myuser:mypassword@localhost:39013?TLSRootCAFile=trust.pem"
// "hdb://myuser:mypassword@localhost:39013?TLSRootCAFile=trust.pem&TLSServerName=hostname"
// "hdb://myuser:mypassword@localhost:39013?TLSInsecureSkipVerify"
|
1.25 Snowflake (pure Go)
https://github.com/snowflakedb/gosnowflake
1
2
3
4
|
jsmith:mypassword@myaccount/mydb/testschema?warehouse=mywh
username[:password]@accountname/dbname/schemaname[?param1=value&...¶mN=valueN
username[:password]@accountname/dbname[?param1=value&...¶mN=valueN
username[:password]@hostname:port/dbname/schemaname?account=<your_account>[¶m1=value&...¶mN=valueN]
|
1.26 SQLite (uses cgo)
https://github.com/gwenn/gosqlite
1
2
3
4
5
6
7
8
|
file:data.db
file:/home/fred/data.db
file:///home/fred/data.db
file://localhost/home/fred/data.db
file:data.db?mode=ro&cache=private
file:/home/fred/data.db?vfs=unix-dotfile
file:data.db?mode=readonly
// ":memory:" for memory db, "" for temp file db
|
1.27 Sybase SQL Anywhere
https://github.com/a-palchikov/sqlago
1
2
3
|
parameter1=value1;parameter2=value2;...
UID=DBA;PWD=sql;Host=demo12;DatabaseName=demo;ServerName=myserver
HOST=myhost;DBN=demo;UID=DBA;PWD=sql;ServerName=demo12
|
1.28 Vitess
https://godoc.org/vitess.io/vitess/go/vt/vitessdriver
1
|
db, err := vitessdriver.Open("localhost:15991", "keyspace", "master", 30*time.Second)
|
2. NoSQL Database
2.1 Memcached
https://github.com/bradfitz/gomemcache
1
|
mc := memcache.New("10.0.0.1:11211", "10.0.0.2:11211", "10.0.0.3:11212")
|
2.2 Mongodb
https://github.com/mongodb/mongo-go-driver
1
|
client, err := mongo.NewClient("mongodb://localhost:27017")
|
2.3 Redis
https://github.com/gomodule/redigo
1
|
c, err := redis.Dial("tcp", ":6379")
|
2.4 redis-go-cluster
https://github.com/chasex/redis-go-cluster
1
2
3
4
5
6
7
8
9
10
|
cluster, err := redis.NewCluster(
&redis.Options{
StartNodes: []string{"127.0.0.1:7000", "127.0.0.1:7001", "127.0.0.1:7002"},
ConnTimeout: 50 * time.Millisecond,
ReadTimeout: 50 * time.Millisecond,
WriteTimeout: 50 * time.Millisecond,
KeepAlive: 16,
AliveTime: 60 * time.Second,
}
)
|
Reference https://colobu.com/2019/01/10/drivers-connection-string-in-Go/