ad_event.go 628 Bytes
package models

import (
	"database/sql"

	db "client/icesimba.ad/database"
)

type Event struct {
	Id   int64
	Code string
	Name string
}

type event struct {
	Id   sql.NullInt64
	Code sql.NullString
	Name sql.NullString
}

func QueryEventByCode(code string) (out Event, err error) {
	sqlQu := "select event_id,event_name from ice_ad_event where event_code=?"
	eventNull := event{}
	err = db.SqlDB.QueryRow(sqlQu, code).Scan(
		&eventNull.Id,
		&eventNull.Name,
	)
	if err != nil {
		return
	}
	if eventNull.Id.Valid {
		out.Id = eventNull.Id.Int64
	}
	if eventNull.Name.Valid {
		out.Name = eventNull.Name.String
	}
	return
}