Skip to content

Instantly share code, notes, and snippets.

@hitsumabushi
Last active August 29, 2015 14:20
Show Gist options
  • Save hitsumabushi/e3c0195d22368361a9ee to your computer and use it in GitHub Desktop.
Save hitsumabushi/e3c0195d22368361a9ee to your computer and use it in GitHub Desktop.
package main
import (
"time"
"github.com/jinzhu/gorm"
_ "github.com/mattn/go-sqlite3"
)
func main() {
// sqlite3
db, _ := gorm.Open("sqlite3", "gorm.db")
// Logger
db.LogMode(true)
db.DB()
db.CreateTable(&Sample{})
}
type Sample struct {
Id uint `sql:"AUTO_INCREMENT"`
LastSeen time.Time `sql:"type:datetime;DEFAULT:'0000-00-00 00:00:00'"` // Contain colon as default value
}
// go run main.go
//=> (/root/src/tmp/main.go:17)
//=> [2015-04-30 07:38:57] [1.94ms] CREATE TABLE "samples" ("id" integer,"last_seen" datetime DEFAULT DEFAULT , PRIMARY KEY (id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment