aboutsummaryrefslogtreecommitdiff
path: root/syncapi
diff options
context:
space:
mode:
authorTill <2353100+S7evinK@users.noreply.github.com>2023-03-23 13:52:53 +0100
committerGitHub <noreply@github.com>2023-03-23 13:52:53 +0100
commit234ed603e6b8c7f1f766a002a097007189e1184e (patch)
tree6b7eefa440f2f98e5addee9cbfca6b218a73ef98 /syncapi
parentcb18ba023084a364a332d09e32ae22d375ed4520 (diff)
Move every `db.Prepare` to `sqlutil.Statementlist`, remove trace driver (#3026)
Doesn't buy us much, but makes everything a bit more consistent. Also removes the SQL trace driver, as it is unused and the output is hard to read anyway.
Diffstat (limited to 'syncapi')
-rw-r--r--syncapi/storage/postgres/account_data_table.go15
-rw-r--r--syncapi/storage/postgres/filter_table.go15
-rw-r--r--syncapi/storage/postgres/ignores_table.go12
-rw-r--r--syncapi/storage/postgres/send_to_device_table.go19
-rw-r--r--syncapi/storage/sqlite3/account_data_table.go15
-rw-r--r--syncapi/storage/sqlite3/filter_table.go15
-rw-r--r--syncapi/storage/sqlite3/ignores_table.go11
-rw-r--r--syncapi/storage/sqlite3/send_to_device_table.go19
-rw-r--r--syncapi/storage/sqlite3/stream_id_table.go7
9 files changed, 44 insertions, 84 deletions
diff --git a/syncapi/storage/postgres/account_data_table.go b/syncapi/storage/postgres/account_data_table.go
index aa54cb08..8147b486 100644
--- a/syncapi/storage/postgres/account_data_table.go
+++ b/syncapi/storage/postgres/account_data_table.go
@@ -78,16 +78,11 @@ func NewPostgresAccountDataTable(db *sql.DB) (tables.AccountData, error) {
if err != nil {
return nil, err
}
- if s.insertAccountDataStmt, err = db.Prepare(insertAccountDataSQL); err != nil {
- return nil, err
- }
- if s.selectAccountDataInRangeStmt, err = db.Prepare(selectAccountDataInRangeSQL); err != nil {
- return nil, err
- }
- if s.selectMaxAccountDataIDStmt, err = db.Prepare(selectMaxAccountDataIDSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.insertAccountDataStmt, insertAccountDataSQL},
+ {&s.selectAccountDataInRangeStmt, selectAccountDataInRangeSQL},
+ {&s.selectMaxAccountDataIDStmt, selectMaxAccountDataIDSQL},
+ }.Prepare(db)
}
func (s *accountDataStatements) InsertAccountData(
diff --git a/syncapi/storage/postgres/filter_table.go b/syncapi/storage/postgres/filter_table.go
index 86cec362..44c3de72 100644
--- a/syncapi/storage/postgres/filter_table.go
+++ b/syncapi/storage/postgres/filter_table.go
@@ -61,16 +61,11 @@ func NewPostgresFilterTable(db *sql.DB) (tables.Filter, error) {
return nil, err
}
s := &filterStatements{}
- if s.selectFilterStmt, err = db.Prepare(selectFilterSQL); err != nil {
- return nil, err
- }
- if s.selectFilterIDByContentStmt, err = db.Prepare(selectFilterIDByContentSQL); err != nil {
- return nil, err
- }
- if s.insertFilterStmt, err = db.Prepare(insertFilterSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.selectFilterStmt, selectFilterSQL},
+ {&s.selectFilterIDByContentStmt, selectFilterIDByContentSQL},
+ {&s.insertFilterStmt, insertFilterSQL},
+ }.Prepare(db)
}
func (s *filterStatements) SelectFilter(
diff --git a/syncapi/storage/postgres/ignores_table.go b/syncapi/storage/postgres/ignores_table.go
index 97660725..a511c747 100644
--- a/syncapi/storage/postgres/ignores_table.go
+++ b/syncapi/storage/postgres/ignores_table.go
@@ -52,13 +52,11 @@ func NewPostgresIgnoresTable(db *sql.DB) (tables.Ignores, error) {
return nil, err
}
s := &ignoresStatements{}
- if s.selectIgnoresStmt, err = db.Prepare(selectIgnoresSQL); err != nil {
- return nil, err
- }
- if s.upsertIgnoresStmt, err = db.Prepare(upsertIgnoresSQL); err != nil {
- return nil, err
- }
- return s, nil
+
+ return s, sqlutil.StatementList{
+ {&s.selectIgnoresStmt, selectIgnoresSQL},
+ {&s.upsertIgnoresStmt, upsertIgnoresSQL},
+ }.Prepare(db)
}
func (s *ignoresStatements) SelectIgnores(
diff --git a/syncapi/storage/postgres/send_to_device_table.go b/syncapi/storage/postgres/send_to_device_table.go
index 6ab1f0f4..88b86ef7 100644
--- a/syncapi/storage/postgres/send_to_device_table.go
+++ b/syncapi/storage/postgres/send_to_device_table.go
@@ -88,19 +88,12 @@ func NewPostgresSendToDeviceTable(db *sql.DB) (tables.SendToDevice, error) {
if err != nil {
return nil, err
}
- if s.insertSendToDeviceMessageStmt, err = db.Prepare(insertSendToDeviceMessageSQL); err != nil {
- return nil, err
- }
- if s.selectSendToDeviceMessagesStmt, err = db.Prepare(selectSendToDeviceMessagesSQL); err != nil {
- return nil, err
- }
- if s.deleteSendToDeviceMessagesStmt, err = db.Prepare(deleteSendToDeviceMessagesSQL); err != nil {
- return nil, err
- }
- if s.selectMaxSendToDeviceIDStmt, err = db.Prepare(selectMaxSendToDeviceIDSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.insertSendToDeviceMessageStmt, insertSendToDeviceMessageSQL},
+ {&s.selectSendToDeviceMessagesStmt, selectSendToDeviceMessagesSQL},
+ {&s.deleteSendToDeviceMessagesStmt, deleteSendToDeviceMessagesSQL},
+ {&s.selectMaxSendToDeviceIDStmt, selectMaxSendToDeviceIDSQL},
+ }.Prepare(db)
}
func (s *sendToDeviceStatements) InsertSendToDeviceMessage(
diff --git a/syncapi/storage/sqlite3/account_data_table.go b/syncapi/storage/sqlite3/account_data_table.go
index de0e72db..eaf52234 100644
--- a/syncapi/storage/sqlite3/account_data_table.go
+++ b/syncapi/storage/sqlite3/account_data_table.go
@@ -66,16 +66,11 @@ func NewSqliteAccountDataTable(db *sql.DB, streamID *StreamIDStatements) (tables
if err != nil {
return nil, err
}
- if s.insertAccountDataStmt, err = db.Prepare(insertAccountDataSQL); err != nil {
- return nil, err
- }
- if s.selectMaxAccountDataIDStmt, err = db.Prepare(selectMaxAccountDataIDSQL); err != nil {
- return nil, err
- }
- if s.selectAccountDataInRangeStmt, err = db.Prepare(selectAccountDataInRangeSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.insertAccountDataStmt, insertAccountDataSQL},
+ {&s.selectMaxAccountDataIDStmt, selectMaxAccountDataIDSQL},
+ {&s.selectAccountDataInRangeStmt, selectAccountDataInRangeSQL},
+ }.Prepare(db)
}
func (s *accountDataStatements) InsertAccountData(
diff --git a/syncapi/storage/sqlite3/filter_table.go b/syncapi/storage/sqlite3/filter_table.go
index 5f1e980e..0132a766 100644
--- a/syncapi/storage/sqlite3/filter_table.go
+++ b/syncapi/storage/sqlite3/filter_table.go
@@ -65,16 +65,11 @@ func NewSqliteFilterTable(db *sql.DB) (tables.Filter, error) {
s := &filterStatements{
db: db,
}
- if s.selectFilterStmt, err = db.Prepare(selectFilterSQL); err != nil {
- return nil, err
- }
- if s.selectFilterIDByContentStmt, err = db.Prepare(selectFilterIDByContentSQL); err != nil {
- return nil, err
- }
- if s.insertFilterStmt, err = db.Prepare(insertFilterSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.selectFilterStmt, selectFilterSQL},
+ {&s.selectFilterIDByContentStmt, selectFilterIDByContentSQL},
+ {&s.insertFilterStmt, insertFilterSQL},
+ }.Prepare(db)
}
func (s *filterStatements) SelectFilter(
diff --git a/syncapi/storage/sqlite3/ignores_table.go b/syncapi/storage/sqlite3/ignores_table.go
index 5ee1a9fa..bff5780b 100644
--- a/syncapi/storage/sqlite3/ignores_table.go
+++ b/syncapi/storage/sqlite3/ignores_table.go
@@ -52,13 +52,10 @@ func NewSqliteIgnoresTable(db *sql.DB) (tables.Ignores, error) {
return nil, err
}
s := &ignoresStatements{}
- if s.selectIgnoresStmt, err = db.Prepare(selectIgnoresSQL); err != nil {
- return nil, err
- }
- if s.upsertIgnoresStmt, err = db.Prepare(upsertIgnoresSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.selectIgnoresStmt, selectIgnoresSQL},
+ {&s.upsertIgnoresStmt, upsertIgnoresSQL},
+ }.Prepare(db)
}
func (s *ignoresStatements) SelectIgnores(
diff --git a/syncapi/storage/sqlite3/send_to_device_table.go b/syncapi/storage/sqlite3/send_to_device_table.go
index 0da06506..998a063c 100644
--- a/syncapi/storage/sqlite3/send_to_device_table.go
+++ b/syncapi/storage/sqlite3/send_to_device_table.go
@@ -88,19 +88,12 @@ func NewSqliteSendToDeviceTable(db *sql.DB) (tables.SendToDevice, error) {
if err != nil {
return nil, err
}
- if s.insertSendToDeviceMessageStmt, err = db.Prepare(insertSendToDeviceMessageSQL); err != nil {
- return nil, err
- }
- if s.selectSendToDeviceMessagesStmt, err = db.Prepare(selectSendToDeviceMessagesSQL); err != nil {
- return nil, err
- }
- if s.deleteSendToDeviceMessagesStmt, err = db.Prepare(deleteSendToDeviceMessagesSQL); err != nil {
- return nil, err
- }
- if s.selectMaxSendToDeviceIDStmt, err = db.Prepare(selectMaxSendToDeviceIDSQL); err != nil {
- return nil, err
- }
- return s, nil
+ return s, sqlutil.StatementList{
+ {&s.insertSendToDeviceMessageStmt, insertSendToDeviceMessageSQL},
+ {&s.selectSendToDeviceMessagesStmt, selectSendToDeviceMessagesSQL},
+ {&s.deleteSendToDeviceMessagesStmt, deleteSendToDeviceMessagesSQL},
+ {&s.selectMaxSendToDeviceIDStmt, selectMaxSendToDeviceIDSQL},
+ }.Prepare(db)
}
func (s *sendToDeviceStatements) InsertSendToDeviceMessage(
diff --git a/syncapi/storage/sqlite3/stream_id_table.go b/syncapi/storage/sqlite3/stream_id_table.go
index a4bba508..b51eccf5 100644
--- a/syncapi/storage/sqlite3/stream_id_table.go
+++ b/syncapi/storage/sqlite3/stream_id_table.go
@@ -47,10 +47,9 @@ func (s *StreamIDStatements) Prepare(db *sql.DB) (err error) {
if err != nil {
return
}
- if s.increaseStreamIDStmt, err = db.Prepare(increaseStreamIDStmt); err != nil {
- return
- }
- return
+ return sqlutil.StatementList{
+ {&s.increaseStreamIDStmt, increaseStreamIDStmt},
+ }.Prepare(db)
}
func (s *StreamIDStatements) nextPDUID(ctx context.Context, txn *sql.Tx) (pos types.StreamPosition, err error) {