Quick Summary
With release 0.0.6, pebl now supports creating mysql instances in both Python and Go.
Longform
Both Python and Go will now have a new method that will initialize a mysql instance on your behalf. The usage is quite similar to the way redis is handled.
Python
In python the method is pebl.mysql
that takes a single string argument to represents the mysql handle. The return value is a dictionary containing four keys, host
, port
, user
, and password
.
These are the exact keys that are needed for pymysql.connect
, and so you can pass the dictionary as keywords args.
import pebl
import pymysql
conn = pebl.mysql("mysql")
db = pymysql.connect(**conn)
with db.cursor() as cursor:
cursor.execute("show databases")
print(cursor.fetchall())
Go
In Go the method is pebl.Mysql
that takes a single string argument to represent the mysql handle. The return value is of type MysqlConn
, which has the necessary fields required to connect to the mysql instance.
package main
import (
"database/sql"
"github.com/peblcloud/go"
"github.com/go-sql-driver/mysql"
)
func main() {
conn, _ := pebl.Mysql("mysql-1")
cfg := mysql.Config{
User: conn.User,
Passwd: conn.Password,
Net: "tcp",
Addr: conn.Addr,
}
db, _ := sql.Open("mysql", cfg.FormatDSN())
if err := db.Ping(); err == nil {
println("Connected!")
}
}
pebl info
When using pebl info
to display information about the local cluster, you will now see entries for any mysql instances that you utilize.
The information will include the local port that you can utilize to connect, which you can pass into mysql:
$ mysql --host 127.0.0.1 --port 32799 -uroot
Upgrading
Make sure to download the latest pebl CLI, which will be needed in order to utilize the new release on your local cluster. Follow the section about installing the CLI in the setup guide.
Go
The Go SDK is available with the 0.0.6 tag. You can update your existing Go projects by running go get -u github.com/peblcloud/go@v0.0.6
.
Python
The Python SDK is available as pre-built docker images. Update your Python projects by changing the Dockerfile
to utilize one of the 0.0.6 images.
Top comments (0)