Added migrations
This commit is contained in:
parent
4a16acc87e
commit
5b18009658
34 changed files with 929 additions and 154 deletions
|
|
@ -19,8 +19,8 @@ func CreatePostRepository(conn *db.Database) PostRepository {
|
|||
}
|
||||
|
||||
func (r *PostRepository) Create(entity *entities.Post) (*entities.Post, error) {
|
||||
query := "INSERT INTO " + entities.PostTable + " (id, userId, title, description, content, createdAt, updatedAt)" +
|
||||
"VALUES (:id, :userId, :title, :description, :content, :createdAt, :updatedAt)"
|
||||
query := "INSERT INTO " + entities.PostTable + " (id, userid, title, description, content, createdat, updatedat)" +
|
||||
"VALUES (:id, :userid, :title, :description, :content, :createdat, :updatedat)"
|
||||
_, err := r.conn.Conn.NamedExec(query, entity)
|
||||
|
||||
return entity, err
|
||||
|
|
@ -43,7 +43,7 @@ func (r *PostRepository) FindById(id uuid.UUID) (*entities.Post, error) {
|
|||
|
||||
func (r *PostRepository) FindAllByUserName(userName string) ([]*entities.Post, error) {
|
||||
var entity_list []*entities.Post
|
||||
query := "SELECT * FROM " + entities.PostTable + " WHERE userId=?"
|
||||
query := "SELECT * FROM " + entities.PostTable + " WHERE userid=?"
|
||||
|
||||
query, args, err := sqlx.In(query, userName)
|
||||
if err != nil {
|
||||
|
|
@ -58,15 +58,15 @@ func (r *PostRepository) FindAllByUserName(userName string) ([]*entities.Post, e
|
|||
|
||||
func (r *PostRepository) GetAll() ([]*entities.Post, error) {
|
||||
var entity_list []*entities.Post
|
||||
query := "SELECT * FROM " + entities.PostTable
|
||||
query := "SELECT * FROM " + entities.PostTable + " ORDER BY createdat, updatedat LIMIT 5;"
|
||||
|
||||
err := r.conn.Conn.Select(entity_list, query)
|
||||
err := r.conn.Conn.Select(&entity_list, query)
|
||||
|
||||
return entity_list, err
|
||||
}
|
||||
|
||||
func (r *PostRepository) Update(entity *entities.Post) error {
|
||||
query := "UPDATE " + entities.PostTable + "SET title=:title, description=:description, content=:content, updatedAt=:updatedAt WHERE id=:id"
|
||||
query := "UPDATE " + entities.PostTable + "SET title=:title, description=:description, content=:content, updatedat=:updatedat WHERE id=:id"
|
||||
|
||||
_, err := r.conn.Conn.NamedExec(query, entity)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue