revel-gorm

module
v0.0.0-...-937b74c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2016 License: MIT

README

revel-gorm

GORM integration module for Revel framework.

Code Climate

Getting Started

Install

% go get github.com/Gr1N/revel-gorm

Documentation

GoDoc

go doc format documentation for this project can be viewed online without installing the package by using the GoDoc page at: http://godoc.org/github.com/Gr1N/revel-gorm

Configuration

Settings can be configured via the following directives in app.conf.

module.db
module.db = github.com/Gr1N/revel-gorm

Please review the documentation at Revel — Modules — Overview for more information.

db.import
db.import = github.com/lib/pq

Golang DB driver.

db.driver
db.driver = postgres

Specifies the name of the database/sql driver.

db.spec
db.spec = "user=username dbname=databasename sslmode=disable"

Specifies the data source name of your database/sql database.

db.max_idle_conns
db.max_idle_conns = 10
db.max_open_conns
db.max_open_conns = 100
db.singular_table
db.singular_table = false

Please review the documentation at GORM — Conventions.

db.log_mode
db.log_mode = false

Please review the documentation at GORM — Logger.

Initialization

Add following code to your app/init.go:

package app

import (
    ...
    "github.com/revel/revel"
    gorm "github.com/Gr1N/revel-gorm/app"
    ...
)

func init() {
    ...
    revel.OnAppStart(func() {
        // Initialize GORM...
        dbm := gorm.InitDB()
        // ...and migrate
        dbm.AutoMigrate(&User{})
    })
    ...
}

And to your app/controllers/init.go:

package controllers

import (
    "github.com/revel/revel"
    gorm "github.com/Gr1N/revel-gorm/app/controllers"
)

func init() {
    revel.InterceptMethod((*gorm.TransactionalController).Begin, revel.BEFORE)
    revel.InterceptMethod((*gorm.TransactionalController).Commit, revel.AFTER)
    revel.InterceptMethod((*gorm.TransactionalController).Rollback, revel.FINALLY)
}

And embed the gorm.TransactionalController on your custom controller:

package controllers

import (
    gorm "github.com/Gr1N/revel-gorm/app/controllers"
)

type Application struct {
    gorm.TransactionalController
}

TODO

  • Documentation
  • Sample application
  • Tests
  • ...

License

revel-gorm is licensed under the MIT license. See the license file for details.

Directories

Path Synopsis
app

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL