From 07a28639f247efcdd65fb49f6d173bc17a1d3a91 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Sat, 27 May 2023 21:36:10 +0200 Subject: [PATCH] There is no need for array_to_string() in tags --- pkg/contacts.go | 4 ++-- pkg/expenses.go | 4 ++-- pkg/invoices.go | 4 ++-- pkg/products.go | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/contacts.go b/pkg/contacts.go index 84b3314..7b969e6 100644 --- a/pkg/contacts.go +++ b/pkg/contacts.go @@ -390,7 +390,7 @@ func (form *contactForm) MustFillFromDatabase(ctx context.Context, conn *Conn, s , province , postal_code , country_code - , array_to_string(tags, ',') + , tags from contact where slug = $1 `, slug).Scan( @@ -414,7 +414,7 @@ func ServeEditContactTags(w http.ResponseWriter, r *http.Request, params httprou company := getCompany(r) slug := params[0].Value form := newTagsForm(companyURI(company, "/contacts/"+slug+"/tags"), slug, locale) - if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select array_to_string(tags, ',') from contact where slug = $1`, form.Slug).Scan(form.Tags)) { + if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select tags from contact where slug = $1`, form.Slug).Scan(form.Tags)) { http.NotFound(w, r) return } diff --git a/pkg/expenses.go b/pkg/expenses.go index 1468205..093adce 100644 --- a/pkg/expenses.go +++ b/pkg/expenses.go @@ -241,7 +241,7 @@ func (form *expenseForm) MustFillFromDatabase(ctx context.Context, conn *Conn, s , invoice_date , to_price(amount, decimal_digits) , array_agg(tax_id) - , array_to_string(tags, ',') + , tags from expense left join expense_tax using (expense_id) join currency using (currency_code) @@ -397,7 +397,7 @@ func ServeEditExpenseTags(w http.ResponseWriter, r *http.Request, params httprou company := getCompany(r) slug := params[0].Value form := newTagsForm(companyURI(company, "/expenses/"+slug+"/tags"), slug, locale) - if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select array_to_string(tags, ',') from expense where slug = $1`, form.Slug).Scan(form.Tags)) { + if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select tags from expense where slug = $1`, form.Slug).Scan(form.Tags)) { http.NotFound(w, r) return } diff --git a/pkg/invoices.go b/pkg/invoices.go index 1bb3392..b19b638 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -722,7 +722,7 @@ func (form *invoiceForm) MustFillFromDatabase(ctx context.Context, conn *Conn, s , invoice_date , notes , payment_method_id - , array_to_string(tags, ',') + , tags from invoice where slug = $1 `, slug).Scan(&invoiceId, form.InvoiceStatus, form.Customer, &form.Number, form.Date, form.Notes, form.PaymentMethod, form.Tags)) { @@ -1066,7 +1066,7 @@ func ServeEditInvoiceTags(w http.ResponseWriter, r *http.Request, params httprou company := getCompany(r) slug := params[0].Value form := newTagsForm(companyURI(company, "/invoices/"+slug+"/tags"), slug, locale) - if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select array_to_string(tags, ',') from invoice where slug = $1`, form.Slug).Scan(form.Tags)) { + if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select tags from invoice where slug = $1`, form.Slug).Scan(form.Tags)) { http.NotFound(w, r) return } diff --git a/pkg/products.go b/pkg/products.go index 76ee7d4..3beb078 100644 --- a/pkg/products.go +++ b/pkg/products.go @@ -321,7 +321,7 @@ func (form *productForm) MustFillFromDatabase(ctx context.Context, conn *Conn, s , product.description , to_price(price, decimal_digits) , array_agg(tax_id) - , array_to_string(tags, ',') + , tags from product left join product_tax using (product_id) join company using (company_id) @@ -359,7 +359,7 @@ func ServeEditProductTags(w http.ResponseWriter, r *http.Request, params httprou company := getCompany(r) slug := params[0].Value form := newTagsForm(companyURI(company, "/products/"+slug+"/tags"), slug, locale) - if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select array_to_string(tags, ',') from product where slug = $1`, form.Slug).Scan(form.Tags)) { + if notFoundErrorOrPanic(conn.QueryRow(r.Context(), `select tags from product where slug = $1`, form.Slug).Scan(form.Tags)) { http.NotFound(w, r) return }