Connecting to a Database

Before any data transaction can occur, you must connect to the database first. First, a reminder on our development configuration in config/database.yml

development:
  dialect: "sqlite3"
  database: "./development.sqlite"

Here's how it's done in main.go.

package main

import (
    "log"
    "github.com/gobuffalo/pop"
)

func main() {
    tx, err := pop.Connect("development")
    if err != nil {
        log.Panic(err)
    }
}

There's not a whole lot going on here, and when you compile it you (hopefully) won't see an error.

$ go build main.go
$ ./main
$

This example isn't very interesting, but sets the basis for future things to do.

results matching ""

    No results matching ""