Renamed account table to user
This commit is contained in:
parent
8c50127dd8
commit
3833353d18
@ -12,22 +12,22 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package account
|
||||
package user
|
||||
|
||||
import "github.com/rs/zerolog/log"
|
||||
|
||||
// Insert a model
|
||||
func (a *Account) Insert(username, password string) error {
|
||||
func (u *User) Insert(name, password string) error {
|
||||
// Store model
|
||||
model := &Model{
|
||||
Username: username,
|
||||
Name: name,
|
||||
Password: password,
|
||||
}
|
||||
|
||||
// Insert model
|
||||
_, err := a.db.Insert(model)
|
||||
_, err := u.db.Insert(model)
|
||||
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
|
||||
}
|
||||
|
@ -12,19 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package account
|
||||
package user
|
||||
|
||||
import "github.com/rs/zerolog/log"
|
||||
|
||||
// Select a model by id
|
||||
func (a *Account) SelectByID(id int) (*Model, error) {
|
||||
func (u *User) SelectByID(id int) (*Model, error) {
|
||||
// Store model
|
||||
model := &Model{}
|
||||
|
||||
// Select model
|
||||
_, err := a.db.Where("i_d = ?", id).Get(model)
|
||||
_, err := u.db.Where("i_d = ?", id).Get(model)
|
||||
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
|
||||
}
|
||||
|
||||
@ -32,14 +32,14 @@ func (a *Account) SelectByID(id int) (*Model, error) {
|
||||
}
|
||||
|
||||
// Select a model by username
|
||||
func (a *Account) SelectByUsername(username string) (*Model, error) {
|
||||
func (u *User) SelectByName(name string) (*Model, error) {
|
||||
// Store model
|
||||
model := &Model{}
|
||||
|
||||
// Select model
|
||||
_, err := a.db.Where("username = ?", username).Get(model)
|
||||
_, err := u.db.Where("name = ?", name).Get(model)
|
||||
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
|
||||
}
|
||||
|
@ -12,7 +12,7 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package account
|
||||
package user
|
||||
|
||||
import (
|
||||
"time"
|
||||
@ -21,26 +21,26 @@ import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
// Account handler
|
||||
type Account struct {
|
||||
// User handler
|
||||
type User struct {
|
||||
db *xorm.Engine
|
||||
}
|
||||
|
||||
// Account model
|
||||
// User model
|
||||
type Model struct {
|
||||
ID int64
|
||||
Username string `xorm:"varchar(30) unique"`
|
||||
Name string `xorm:"varchar(30) unique"`
|
||||
Password string `xorm:"varchar(90)"`
|
||||
Created time.Time `xorm:"created"`
|
||||
}
|
||||
|
||||
// Return a new Account
|
||||
func New(engine *xorm.Engine) *Account {
|
||||
// Return a new User
|
||||
func New(engine *xorm.Engine) *User {
|
||||
// Sync engine
|
||||
err := engine.Sync(new(Model))
|
||||
if err != nil {
|
||||
log.Panic().Msg(err.Error())
|
||||
}
|
||||
|
||||
return &Account{db: engine}
|
||||
return &User{db: engine}
|
||||
}
|
Loading…
Reference in New Issue
Block a user