1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- package fetdata
- import (
- "golang-fave/engine/utils"
- "golang-fave/engine/wrapper"
- )
- type User struct {
- wrap *wrapper.Wrapper
- object *utils.MySql_user
- }
- func (this *User) load() *User {
- return this
- }
- func (this *User) loadById(id int) {
- if this == nil {
- return
- }
- if this.object != nil {
- return
- }
- this.object = &utils.MySql_user{}
- if err := this.wrap.DB.QueryRow(
- this.wrap.R.Context(),
- `SELECT
- id,
- first_name,
- last_name,
- email,
- admin,
- active
- FROM
- fave_users
- WHERE
- id = ?
- LIMIT 1;`,
- id,
- ).Scan(
- &this.object.A_id,
- &this.object.A_first_name,
- &this.object.A_last_name,
- &this.object.A_email,
- &this.object.A_admin,
- &this.object.A_active,
- ); *this.wrap.LogCpError(&err) != nil {
- return
- }
- }
- func (this *User) Id() int {
- if this == nil {
- return 0
- }
- return this.object.A_id
- }
- func (this *User) FirstName() string {
- if this == nil {
- return ""
- }
- return this.object.A_first_name
- }
- func (this *User) LastName() string {
- if this == nil {
- return ""
- }
- return this.object.A_last_name
- }
- func (this *User) Email() string {
- if this == nil {
- return ""
- }
- return this.object.A_email
- }
- func (this *User) IsAdmin() bool {
- if this == nil {
- return false
- }
- return this.object.A_admin == 1
- }
- func (this *User) IsActive() bool {
- if this == nil {
- return false
- }
- return this.object.A_active == 1
- }
|