com_mysql

package
v0.0.0-...-3d4fdec Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Examples

Constants

View Source
const (
	DriverName = "mysql"

	DSN = "MYSQL_DSN"
)

Variables

This section is empty.

Functions

func GetEnv

func GetEnv() (halfDsn string)
Example
package main

import (
	"database/sql"
	"fmt"

	"github.com/zhangxiaofeng05/com/db/com_mysql"
)

func main() {
	// $ go get github.com/go-sql-driver/mysql

	// import _ "github.com/go-sql-driver/mysql"
	halfDsn := com_mysql.GetEnv()
	dsn := fmt.Sprintf("%s/%s?parseTime=true", halfDsn, "dev")
	fmt.Println(dsn)
	db, err := sql.Open(com_mysql.DriverName, dsn)
	if err != nil {
		panic(err)
	}
	defer db.Close()
	err = db.Ping()
	if err != nil {
		panic(err)
	}
}
Output:

func Gorm

func Gorm(dsn string) (gormDB *gorm.DB, err error)

func Sql

func Sql(dsn string) (sqlDB *sql.DB, err error)

Sql Standard library

func Sqlx

func Sqlx(dsn string) (sqlxDB *sqlx.DB, err error)

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL