Package google.golang.org/appengine/cloudsql (v1.6.7)
Stay organized with collections
Save and categorize content based on your preferences.
Version 1.6.7 keyboard_arrow_down
Package cloudsql exposes access to Google Cloud SQL databases.
This package does not work in App Engine "flexible environment".
This package is intended for MySQL drivers to make App Engine-specific
connections. Applications should use this package through database/sql:
Select a pure Go MySQL driver that supports this package, and use sql.Open
with protocol "cloudsql" and an address of the Cloud SQL instance.
A Go MySQL driver that has been tested to work well with Cloud SQL
is the go-sql-driver:
import "database / sql "
import _ "github . com / go - sql - driver / mysql "
db , err : = sql . Open ( "mysql ", "user @ cloudsql ( project - id : instance - name ) / dbname ")
Another driver that works well with Cloud SQL is the mymysql driver:
import "database / sql "
import _ "github . com / ziutek / mymysql / godrv "
db , err : = sql . Open ( "mymysql ", "cloudsql : instance - name * dbname / user / password ")
Using either of these drivers, you can perform a standard SQL query.
This example assumes there is a table named 'users' with
columns 'first_name' and 'last_name':
rows , err : = db . Query ( "SELECT first_name , last_name FROM users ")
if err != nil {
log . Errorf ( ctx , "db . Query : % v ", err )
}
defer rows . Close ()
for rows . Next () {
var firstName string
var lastName string
if err : = rows . Scan ( &firstName , &lastName ); err != nil {
log . Errorf ( ctx , "rows . Scan : % v ", err )
continue
}
log . Infof ( ctx , "First : % v - Last : % v ", firstName , lastName )
}
if err : = rows . Err (); err != nil {
log . Errorf ( ctx , "Row error : % v ", err )
}
Functions
func Dial
Dial connects to the named Cloud SQL instance.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-09-19 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-09-19 UTC."}
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-09-19 UTC."]]