8000 Documentation: CreateTable is misleading in "Basic Example" · Issue #73 · eaigner/hood · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Documentation: CreateTable is misleading in "Basic Example" #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hahnicity opened this issue Sep 11, 2013 · 1 comment
Open

Documentation: CreateTable is misleading in "Basic Example" #73

hahnicity opened this issue Sep 11, 2013 · 1 comment

Comments

@hahnicity
Copy link

You show in your "Basic Example":

func main() {
    // Open a DB connection, use New() alternatively for unregistered dialects
    hd, err := hood.Open("postgres", "user=hood dbname=hood_test sslmode=disable")
    if err != nil {
        panic(err)
    }

    // Create a table
    type Fruit struct {
        Id    hood.Id
        Name  string `validate:"presence"`
        Color string
    } 

    err = hd.CreateTable(&Fruit{})

However when I try to replicate this flow myself I receive an error saying

    panic: CreateTable can only be invoked inside a transaction
@hahnicity
Copy link
Author

So not only is there an error in order of the function call but there is also an error in variable naming as well

    err = hd.CreateTable(&Fruit{})

Should look something like:

    tx := hd.Begin()
    err = tx.CreateTable(&Fruit{})

hahnicity added a commit to hahnicity/hood that referenced this issue Sep 11, 2013
Fixed the basic example so that CreateTable is called inside a transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant
0