MySQL tinyint save to table

I have one filed in MySQL which is of type tinyint and go struct is Boolean .

While saving reports are not get saved.

How to manage this

You need to map boolean → int, for example:

type User struct {
    Username string
    Email string
    Acitve bool
}

u := new(User)
var active int

stmt.QueryRow(email).Scan(&u.Username, &u.Email, &active)

if active == 0 {
    u.Active = false
} else {
    u.Active = true
}

If I have one hundred thousand records. I have loop unnecessary

you can try ent

this is a demo struct

package schema

import (
	"entgo.io/ent"
	"entgo.io/ent/dialect/entsql"
	"entgo.io/ent/schema"
	"entgo.io/ent/schema/field"
)

type Demo struct {
	ent.Schema
}

func (Demo) Fields() []ent.Field {
	return []ent.Field{
		field.Uint64("id").Unique(),
		field.String("name"),
		field.Bool("is_delete"),
	}
}

func (Demo) Edges() []ent.Edge {
	return []ent.Edge{}
}

func (DhExpert) Demo() []schema.Annotation {
	return []schema.Annotation{entsql.Annotation{Table: "demo"}}
}

you can Create like:

	sdn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s", "root", "123456", "192.168.1.203", 3306, "ent_test")

	client, err := ent.Open("mysql", sdn)
	if err != nil {
		log.Fatalf("failed opening connection to sqlite: %v", err)
	}
	defer client.Close()
	ctx := context.Background()

	// Run the auto migration tool.
	if err := client.Schema.Create(ctx); err != nil {
		log.Fatalf("failed creating schema resources: %v", err)
	}
      // create 
	cli.Debug().Demo.Create().SetID(1).SetName("xx").SetIsDelete(false).SaveX(ctx)

    // query
	xx, _ := client.Demo.Query().All(context.Background())
	for _, v := range xx {
		fmt.Printf("%v\n", v)
	}