create-go-app / fiber-go-template

📝 Production-ready backend template with Fiber Go Web Framework for Create Go App CLI.
https://github.com/create-go-app/cli/wiki
Apache License 2.0
955 stars 120 forks source link

GetBooks returns empty #98

Closed dhinojosac closed 2 years ago

dhinojosac commented 2 years ago

I changed the method of sqlx to get all book in backend/app/queries/book_query.go: err := q.Select(&books, "SELECT * FROM books")

Now, it's working!

welcome[bot] commented 2 years ago

Thanks for opening your first issue here! 🎉 Be sure to follow the issue template!

koddr commented 2 years ago

Hi,

What do you mean, “it's working”? What kind of error or stack is output? To give more information, so far, it is not clear either the cause of the error or how to reproduce it to fix it (if it is confirmed, of course).

dhinojosac commented 2 years ago

Sorry for the lack of information. The function used to get all books in the template was the way to get a single result, for this way the return is always empty:

    // You can also get a single result, a la QueryRow
    jason = Person{}
    err = db.Get(&jason, "SELECT * FROM person WHERE first_name=$1", "Jason")
    fmt.Printf("%#v\n", jason)

But since we want can to obtain the list of all books, we must use this other function (as it says in the documentation of jmoiron/sqlx):

// if you have null fields and use SELECT *, you must use sql.Null* in your struct
    places := []Place{}
    err = db.Select(&places, "SELECT * FROM place ORDER BY telcode ASC")
    if err != nil {
        fmt.Println(err)
        return
    }

That's it! I hope it's useful! Thanks

stale[bot] commented 2 years ago

👋 Hello. Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] commented 2 years ago

⚡️ This issue has been automatically closed because it has not had recent activity.