mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-21 05:43:09 -06:00
Use RETURNING because LastInsertID is not supported by postgres
This commit is contained in:
parent
693928396d
commit
a6aaa5aa52
|
|
@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS federationsender_queue_json (
|
||||||
const insertJSONSQL = "" +
|
const insertJSONSQL = "" +
|
||||||
"INSERT INTO federationsender_queue_json (json_body)" +
|
"INSERT INTO federationsender_queue_json (json_body)" +
|
||||||
" VALUES ($1)" +
|
" VALUES ($1)" +
|
||||||
" ON CONFLICT DO NOTHING"
|
" RETURNING json_nid"
|
||||||
|
|
||||||
const deleteJSONSQL = "" +
|
const deleteJSONSQL = "" +
|
||||||
"DELETE FROM federationsender_queue_json WHERE json_nid = ANY($1)"
|
"DELETE FROM federationsender_queue_json WHERE json_nid = ANY($1)"
|
||||||
|
|
@ -75,12 +75,11 @@ func (s *queueJSONStatements) insertQueueJSON(
|
||||||
ctx context.Context, txn *sql.Tx, json string,
|
ctx context.Context, txn *sql.Tx, json string,
|
||||||
) (int64, error) {
|
) (int64, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.insertJSONStmt)
|
stmt := sqlutil.TxStmt(txn, s.insertJSONStmt)
|
||||||
res, err := stmt.ExecContext(ctx, json)
|
var lastid int64
|
||||||
if err != nil {
|
if err := stmt.QueryRowContext(ctx, json).Scan(&lastid); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
lastid, err := res.LastInsertId()
|
return lastid, nil
|
||||||
return lastid, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *queueJSONStatements) deleteQueueJSON(
|
func (s *queueJSONStatements) deleteQueueJSON(
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS federationsender_queue_json (
|
||||||
const insertJSONSQL = "" +
|
const insertJSONSQL = "" +
|
||||||
"INSERT INTO federationsender_queue_json (json_body)" +
|
"INSERT INTO federationsender_queue_json (json_body)" +
|
||||||
" VALUES ($1)" +
|
" VALUES ($1)" +
|
||||||
" ON CONFLICT DO NOTHING"
|
" RETURNING json_nid"
|
||||||
|
|
||||||
const deleteJSONSQL = "" +
|
const deleteJSONSQL = "" +
|
||||||
"DELETE FROM federationsender_queue_json WHERE json_nid = ANY($1)"
|
"DELETE FROM federationsender_queue_json WHERE json_nid = ANY($1)"
|
||||||
|
|
@ -75,12 +75,11 @@ func (s *queueJSONStatements) insertQueueJSON(
|
||||||
ctx context.Context, txn *sql.Tx, json string,
|
ctx context.Context, txn *sql.Tx, json string,
|
||||||
) (int64, error) {
|
) (int64, error) {
|
||||||
stmt := sqlutil.TxStmt(txn, s.insertJSONStmt)
|
stmt := sqlutil.TxStmt(txn, s.insertJSONStmt)
|
||||||
res, err := stmt.ExecContext(ctx, json)
|
var lastid int64
|
||||||
if err != nil {
|
if err := stmt.QueryRowContext(ctx, json).Scan(&lastid); err != nil {
|
||||||
return 0, err
|
return 0, err
|
||||||
}
|
}
|
||||||
lastid, err := res.LastInsertId()
|
return lastid, nil
|
||||||
return lastid, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *queueJSONStatements) deleteQueueJSON(
|
func (s *queueJSONStatements) deleteQueueJSON(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue