Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9022891
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T05:37:47+00:00 2026-06-16T05:37:47+00:00

I have a struct that looks like: type inv struct { ID int `json:id`

  • 0

I have a struct that looks like:

type inv struct {
    ID   int     `json:"id"`
    Name string  `json:"name"`
}

I’m querying some data from the database(assuming there are no errors):

rows, err := db.Query("select id, name from inv_table")

Normally, I’d have to pull the data from the row by scanning

var i inv
for rows.Next() {
    rows.Scan(&i.ID, &i.Name)
}

I think this might work (to be tested tomorrow):

var i inv
for rows.Next() {
    var x []interface{} = [&i.ID, &i.Name]
    rows.Scan(x... )
}

In actuality I have many more columns in the result set from the query.

rows.Scan(&i)

or at least:

rows.Scan(getExportedValuePointers(&i)... )

I suppose I could always write some sort of encoder, however, it seems to me that there should be something in the box already.

** I realize that I could always write some reflection code similar to the encode/xml or encode/json … but I’m hoping that someone has already done it.

UPDATE: The following code works as expected but not as I want:

package main
import "fmt"
type inv struct {
    A int
    B string
}
func main() {
    var i inv
    fmt.Printf("hello\n")
    n, err := fmt.Sscan("1 c", &i.A, &i.B)
    fmt.Printf("retval: %d %#v\n", n, err)
    fmt.Printf("retval: %d, %s, %d %#v\n", i.A, i.B, n, err)
    j := []interface{}{&i.A, &i.B}
    k := []interface{}{i.A, i.B}
    n, err = fmt.Sscan("2 d", j... )
    fmt.Printf("retval: %d, %s, %d %#v\n", i.A, i.B, n, err)
    fmt.Printf("retval: %d, %s\n", k... )
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T05:37:49+00:00Added an answer on June 16, 2026 at 5:37 am

    If you’re looking for a package that will automatically bind your SQL query to your “inv” struct then take a look at gorp:

    https://github.com/coopernurse/gorp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a code that looks something like: struct Data { int value; };
I have a message definition file that looks like this struct1 { field=name type=string
I have a struct that looks like this, struct Foo { int a; };
I have a struct that looks like this: typedef struct _my_struct { float first_vector[SOME_NUM][OTHER_NUM];
I have a struct that looks something like: struct foo_t { template <std::size_t x,
I have a struct that looks something like this: [StructLayout(LayoutKind.Sequential)] public struct in_addr {
I have an unmanaged struct I'd like to marshal to c sharp that looks
I have a C structure that looks like this typedef struct event_queue{ Event* event;
I have code in my header file that looks like: typedef struct _bn bnode;
My struct looks like this: struct tlv_msg { uint8_t datatype; //type of data /*

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.