go_import_excel_pg/internal/repository/alamat.repository.go
2024-02-23 14:10:40 +07:00

55 lines
960 B
Go

package repository
import (
"context"
"time"
"git.nochill.in/nochill/excel_import_playground/model"
"github.com/jackc/pgx/v5"
)
func (q *Queries) CreateAlamat(ctx context.Context, arg model.Alamat) (model.Alamat, error) {
createAlamatQuery := `
INSERT INTO "Alamat" (
kategori,
negara,
provinsi,
kabupaten,
kecamatan,
kelurahan,
kode_pos,
nama_jalan,
rt,
rw,
no_hp,
no_telpon,
pasien_id,
status,
updated_at
) VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15)
RETURNING *
`
row, _ := q.db.Query(ctx, createAlamatQuery,
arg.Kategori,
arg.Negara,
arg.Provinsi,
arg.Kabupaten,
arg.Kecamatan,
arg.Kelurahan,
arg.Kode_pos,
arg.Nama_jalan,
arg.Rt,
arg.Rw,
arg.No_hp,
arg.No_telpon,
arg.Pasien_id,
arg.Status,
time.Now().UTC(),
)
result, err := pgx.CollectExactlyOneRow[model.Alamat](row, pgx.RowToStructByName[model.Alamat])
return result, err
}