Change the project layout
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"time"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
id int
|
||||
created_at time.Time
|
||||
name sql.NullString
|
||||
username string
|
||||
password string
|
||||
}
|
||||
|
||||
func Create(db *sql.DB, username string, password string) (*User, error) {
|
||||
//TODO: Hash password, plaintext is dumb and unsafe
|
||||
row := db.QueryRow("INSERT INTO users(username, password) VALUES (?, ?) RETURNING id, created_at, name, username;", username, password)
|
||||
user := &User{}
|
||||
err := row.Scan(&user.id, &user.created_at, &user.name, &user.username)
|
||||
return user, err
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
dbpkg "nkeller.dev/blog_software/db"
|
||||
)
|
||||
|
||||
func Delete(db *sql.DB, id int) {
|
||||
result, err := db.Exec("DELETE FROM users WHERE id = ?;", id)
|
||||
dbpkg.CheckError(err)
|
||||
_ = result
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
package user
|
||||
|
||||
Reference in New Issue
Block a user