In order to connect to a database, you need to import the database’s driver first. For example:
import _ "github.com/go-sql-driver/mysql"
GORM has wrapped some drivers to make it easier to remember the import path. So you could import the mysql driver with:
import _ "github.com/jinzhu/gorm/dialects/mysql"
In order to handle
time.Time correctly, you need to include
parseTime as a parameter. (More supported parameters)
In order to fully support UTF-8 encoding, you need to change
charset=utf8mb4. See this article for a detailed explanation.
NOTE: You can also use
:memory: instead of a path to a file. This will tell sqlite to use a temporary database in system memory. This is especially useful when writing tests for your application against GORM, your tests to hit an actual database, but also be performant as the database is located in memory.
GORM officially supports above four databases, you could write dialects for unsupported databases, refer GORM Dialects