From 3646ea5aec282481806d80cfae46ac94aa810c26 Mon Sep 17 00:00:00 2001 From: Victor Lacasse-Beaudoin Date: Mon, 16 Sep 2024 14:49:56 -0400 Subject: [PATCH] =?UTF-8?q?format(db):=20a=C3=A9rer=20et=20standardiser=20?= =?UTF-8?q?requ=C3=AAtes=20SQL=20dans=20DataClient?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- data/dataclient.go | 39 +++++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/data/dataclient.go b/data/dataclient.go index df6fe32..c4be53e 100644 --- a/data/dataclient.go +++ b/data/dataclient.go @@ -90,7 +90,24 @@ func (d *DataClient) InsertTransactions(transactions []models.Transaction) ([]mo return rowsInserted, errors.New("Impossible d'insérer une transaction sans membre_id") } - rows, err := tx.NamedQuery("INSERT INTO transactions (membre_id, given_at, is_perpetual) VALUES (:membre_id, current_timestamp, :is_perpetual) RETURNING id, membre_id, is_perpetual;", &transaction) + rows, err := tx.NamedQuery(` +INSERT INTO + transactions ( + membre_id, + given_at, + is_perpetual + ) +VALUES + ( + :membre_id, + current_timestamp, + :is_perpetual + ) +RETURNING + id, + membre_id, + is_perpetual; +`, &transaction) if err != nil { return rowsInserted, err } @@ -117,8 +134,16 @@ func (d *DataClient) InsertTransactions(transactions []models.Transaction) ([]mo func (d *DataClient) GetTransaction(membreID string, is_perpetual bool) (models.Transaction, error) { var transaction models.Transaction - //err := d.DB.NamedQuery("SELECT * FROM transactions WHERE membre_id=:membre_id AND is_perpetual=:is_perpetual LIMIT 1;" - err := d.DB.Get(&transaction, "SELECT * FROM transactions WHERE membre_id = $1 AND is_perpetual = $2 LIMIT 1;", membreID, is_perpetual) + err := d.DB.Get(&transaction, ` +SELECT + * +FROM + transactions +WHERE + membre_id = $1 AND + is_perpetual = $2 +LIMIT 1; +`, membreID, is_perpetual) if err != nil { return transaction, err } @@ -132,7 +157,13 @@ func (d *DataClient) GetTransaction(membreID string, is_perpetual bool) (models. func (d *DataClient) ListTransactions() ([]models.Transaction, error) { var transactions []models.Transaction - if err := d.DB.Select(&transactions, "SELECT * FROM transactions LIMIT 20000;"); err != nil { + if err := d.DB.Select(&transactions, ` +SELECT + * +FROM + transactions +LIMIT 20000; +`); err != nil { return transactions, err }