주의할점: time.Time 을 정확하게 다루기 위하여 먼저 parseTime을 인자로서 포함해주세요. (더 많은 인자를 고려하기) UTF-8 인코딩을 완전히 지원하기 위하여 charset=utf8을 charset=utf8mb4 로 바꿔주세요. 해당 기사를 통해 더욱 자세한 사항을 확인할 수 있습니다.
MySQL 드라이버는 다음과 같이 생성시 사용될 수 있는 향상된 추가 설정을 지원합니다. 예시:
db, err := gorm.Open(mysql.New(mysql.Config{ DSN: "gorm:gorm@tcp(127.0.0.1:3306)/gorm?charset=utf8&parseTime=True&loc=Local", // data source name DefaultStringSize: 256, // default size for string fields DisableDatetimePrecision: true, // disable datetime precision, which not supported before MySQL 5.6 DontSupportRenameIndex: true, // drop & create when rename index, rename index not supported before MySQL 5.7, MariaDB DontSupportRenameColumn: true, // `change` when rename column, rename column not supported before MySQL 8, MariaDB SkipInitializeWithVersion: false, // auto configure based on currently MySQL version }), &gorm.Config{})
Customize Driver
GORM은 드라이버 이름 옵션을 통해 MySQL 드라이버를 Customize하는 것을 지원합니다. 예시:
The GORM Driver for Oracle provides support for Oracle Database, enabling full compatibility with GORM’s ORM capabilities. It is built on top of the Go Driver for Oracle (Godror) and supports key features such as auto migrations, associations, transactions, and advanced querying.
Prerequisite: Install Instant Client
To use ODPI-C with Godror, you’ll need to install the Oracle Instant Client on your system. Follow the steps on this page to complete the installation.
After that, you can connect to the database using the dataSourceName, which specifies connection parameters (such as username and password) using a logfmt-encoded parameter list.
The way you specify the Instant Client directory differs by platform:
macOS and Windows: You can set the libDir parameter in the dataSourceName.
Linux: The libraries must be in the system library search path before your Go process starts, preferably configured with “ldconfig”. The libDir parameter does not work on Linux.
import ( "gorm.io/driver/sqlite"// Sqlite driver based on CGO // "github.com/glebarez/sqlite" // Pure go SQLite driver, checkout https://github.com/glebarez/sqlite for details "gorm.io/gorm" )
NOTE: You can also use file::memory:?cache=shared instead of a path to a file. 이 경우 SQLite는 시스템의 메모리에 있는 임시적인 DataBase를 활용할 것 입니다. (SQLite docs를 참고하세요)