Entity Object

Example

import (
	. "github.com/doytowin/goooqo"
)

type UserEntity struct {
	Int64Id
	Name  *string `json:"name,omitempty"`
	Score *int    `json:"score,omitempty"`
	Memo  *string `json:"memo,omitempty"`
}

func (u UserEntity) GetTableName() string {
	return "t_user"
}

Definition

An entity object is used to provide the table name and column names for CRUD statements construction in GoooQo.

The entity struct needs to implement the following interface:

  • GetId is used to build a Update statement.

  • SetId is used to set the generated ID to an entity.

  • GetTableName is used to provide the table name corresponding to the entity.

  • Each field in the entity needs to correspond to a column in the table.

GoooQo provides two Entity implementations, IntId and Int64Id, to simplify entity definition.

The CRUD statements of the UserEntity in the example are:

Last updated

Was this helpful?