mirror of
https://github.com/yanislav-igonin/micrach
synced 2024-12-22 14:22:33 +03:00
refac: move sql stmt
This commit is contained in:
parent
1d93c5621d
commit
1323d83032
@ -16,6 +16,12 @@ func (r *PostsRepository) Get(limit, offset int) ([]Post, error) {
|
||||
return PostsDb, nil
|
||||
}
|
||||
|
||||
conn, err := Db.Pool.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Release()
|
||||
|
||||
sql := `
|
||||
SELECT id, title, text, created_at
|
||||
FROM posts
|
||||
@ -26,12 +32,6 @@ func (r *PostsRepository) Get(limit, offset int) ([]Post, error) {
|
||||
LIMIT $1
|
||||
`
|
||||
|
||||
conn, err := Db.Pool.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer conn.Release()
|
||||
|
||||
rows, err := conn.Query(context.TODO(), sql, limit)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -55,18 +55,18 @@ func (r *PostsRepository) Get(limit, offset int) ([]Post, error) {
|
||||
}
|
||||
|
||||
func (r *PostsRepository) Create(p Post) (int, error) {
|
||||
sql := `
|
||||
INSERT INTO posts (is_parent, parent_id, title, text, is_sage)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
conn, err := Db.Pool.Acquire(context.TODO())
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
defer conn.Release()
|
||||
|
||||
sql := `
|
||||
INSERT INTO posts (is_parent, parent_id, title, text, is_sage)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
RETURNING id
|
||||
`
|
||||
|
||||
var row pgx.Row
|
||||
if p.IsParent {
|
||||
row = conn.QueryRow(
|
||||
|
Loading…
Reference in New Issue
Block a user