Renamed account table to user

This commit is contained in:
perp 2024-06-03 12:52:17 +01:00
parent 8c50127dd8
commit 3833353d18
3 changed files with 20 additions and 20 deletions

View File

@ -12,22 +12,22 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package account package user
import "github.com/rs/zerolog/log" import "github.com/rs/zerolog/log"
// Insert a model // Insert a model
func (a *Account) Insert(username, password string) error { func (u *User) Insert(name, password string) error {
// Store model // Store model
model := &Model{ model := &Model{
Username: username, Name: name,
Password: password, Password: password,
} }
// Insert model // Insert model
_, err := a.db.Insert(model) _, err := u.db.Insert(model)
if err != nil { if err != nil {
log.Err(err).Str("table", "account").Msg("Could not insert row") log.Err(err).Str("table", "user").Msg("Could not insert row")
return err return err
} }

View File

@ -12,19 +12,19 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package account package user
import "github.com/rs/zerolog/log" import "github.com/rs/zerolog/log"
// Select a model by id // Select a model by id
func (a *Account) SelectByID(id int) (*Model, error) { func (u *User) SelectByID(id int) (*Model, error) {
// Store model // Store model
model := &Model{} model := &Model{}
// Select model // Select model
_, err := a.db.Where("i_d = ?", id).Get(model) _, err := u.db.Where("i_d = ?", id).Get(model)
if err != nil { if err != nil {
log.Err(err).Str("table", "account").Str("type", "id").Msg("Could not select row") log.Err(err).Str("table", "user").Str("type", "id").Msg("Could not select row")
return nil, err return nil, err
} }
@ -32,14 +32,14 @@ func (a *Account) SelectByID(id int) (*Model, error) {
} }
// Select a model by username // Select a model by username
func (a *Account) SelectByUsername(username string) (*Model, error) { func (u *User) SelectByName(name string) (*Model, error) {
// Store model // Store model
model := &Model{} model := &Model{}
// Select model // Select model
_, err := a.db.Where("username = ?", username).Get(model) _, err := u.db.Where("name = ?", name).Get(model)
if err != nil { if err != nil {
log.Err(err).Str("table", "account").Str("type", "username").Msg("Could not select row") log.Err(err).Str("table", "user").Str("type", "name").Msg("Could not select row")
return nil, err return nil, err
} }

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and // See the License for the specific language governing permissions and
// limitations under the License. // limitations under the License.
package account package user
import ( import (
"time" "time"
@ -21,26 +21,26 @@ import (
"xorm.io/xorm" "xorm.io/xorm"
) )
// Account handler // User handler
type Account struct { type User struct {
db *xorm.Engine db *xorm.Engine
} }
// Account model // User model
type Model struct { type Model struct {
ID int64 ID int64
Username string `xorm:"varchar(30) unique"` Name string `xorm:"varchar(30) unique"`
Password string `xorm:"varchar(90)"` Password string `xorm:"varchar(90)"`
Created time.Time `xorm:"created"` Created time.Time `xorm:"created"`
} }
// Return a new Account // Return a new User
func New(engine *xorm.Engine) *Account { func New(engine *xorm.Engine) *User {
// Sync engine // Sync engine
err := engine.Sync(new(Model)) err := engine.Sync(new(Model))
if err != nil { if err != nil {
log.Panic().Msg(err.Error()) log.Panic().Msg(err.Error())
} }
return &Account{db: engine} return &User{db: engine}
} }