Instantly share code, notes, and snippets.

@protosam /main.go
Last active Sep 4, 2018

Embed
What would you like to do?
package main
import (
"fmt"
"./model"
)
func main(){
defer model.Close()
var user model.User
user.Init(&user)
user.Name = "John Smith"
user.Email = "john.smith@abc.xyz"
user.Create()
user.FindWhere("name = ?", "John Smith")
for user.Each() {
fmt.Println(user.Id)
fmt.Println(user.Name)
fmt.Println(user.Email)
user.Blah = "Something something darkside"
user.Save()
user.Delete()
}
}
package model // This is actually filename: "model/users.go"
import (
. "./myorm"
"time"
)
type User struct {
MODEL
Id int64 `options:"NOT NULL" PRIMARY_KEY AUTO_INCREMENT`
DisplayName string
Email string `type:"VARCHAR(255)"`
Birthdate time.Time `mysql_type:"date"`
Admin bool
Verified bool
TABLE `users`
OPTIONS `ENGINE=InnoDB CHARACTER SET utf8`
//myorm.JOIN_FRAGMENT `LEFT JOIN users_xtrainfo ON users.id = users_xtrainfo.`
}
func init(){
Connect("DATABASE_USERNAME:DATABASE_PASSWORD@tcp(DATABASE_HOST:3306)/DATABASE_NAME?charset=utf8&parseTime=True&loc=Local")
AutoMigrate(&User{}) // AutoMigrate will automatically create the table and add missing fields.
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment