Revel does not come configured with a database or ORM interface. There are modules like GORM that can be used to provide this functionality. But ultimately it’s up to the developer what to use and how to use.


  • The appconf does have a database section for usage.
  • Use revel.Config to access.
    func InitDB() {
      driver := revel.Config.StringDefault("db.driver", "mysql")
      connect_string := revel.Config.StringDefault("db.connect", "root:root@localhost/test")
      Db, err = sql.Open(driver, connect_string)

Example Db Setup

Create an InitDB() function in for example

package app

import (
    _ ""

var DB *sql.DB

func InitDB() {
    connstring := fmt.Sprintf("user=%s password='%s' dbname=%s sslmode=disable", "user", "pass", "database")

    var err error
    DB, err = sql.Open("postgres", connstring)
    if err != nil {
        revel.INFO.Println("DB Error", err)
    revel.INFO.Println("DB Connected")

func init() {

    revel.Filters = []revel.Filter{
        revel.PanicFilter,             // Recover from panics and display an error page instead.
        ... snipped ...
        revel.CompressFilter,          // Compress the result.
        revel.ActionInvoker,           // Invoke the action.

This can then be used in code


func GetStuff() MyStruct {

    sql := "SELECT id, name from my_table "
    rows, err := app.DB.Query(sql)
    ... do stuff here ...

GoDoc Reference
GitHub Labels