Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

kwiscale/orm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ORM - Gorm Wrapper for Kwiscale

Coverage StatusBuild Status

Gorm is a complete ORM for Go. Kwiscale/Gorm is a simple wrapper to be able to implement database in framework.

Usage

In your main package, simply import and initialize database connection.

package main

import (
	"gopkg.in/kwiscale/framework.v1"
	"gopkg.in/kwiscale/orm.v1"
	_ "gopkg.in/kwiscale/orm.v1/dialects/sqlite"
)

// User is a simple orm.Model
type User struct {
	orm.Model
	Name string
	Age  int
}

func init() {
	orm.Initialize("sqlite", "./test.db")
	db := orm.Get()
	defer db.Close()
    // Create table, update if needed
	db.AutoMigrate(&User{})
}

Then, you may insert, delete, find, and so on.

user := User{
    Name: "Foo",
    Age: 42,
}

db := orm.Get()
defer db.Close()

db.Create(&user)

// find a user and set it on
// "res" structure
res:=User{}
db.First(&res, &User{Name:"Foo"})

To get more information on requests, see Gorm documentation

Releases

No releases published

Packages

No packages published

Languages