From 3b07633326ae7be1b96928fe9576ecf62f0aa149 Mon Sep 17 00:00:00 2001 From: Mark Haines Date: Wed, 2 Aug 2017 16:50:34 +0100 Subject: [PATCH] Simplify preparing the roomserver SQL (#172) --- .../dendrite/roomserver/storage/sql.go | 48 ++++++------------- 1 file changed, 14 insertions(+), 34 deletions(-) diff --git a/src/github.com/matrix-org/dendrite/roomserver/storage/sql.go b/src/github.com/matrix-org/dendrite/roomserver/storage/sql.go index 1f247b55..ddab2356 100644 --- a/src/github.com/matrix-org/dendrite/roomserver/storage/sql.go +++ b/src/github.com/matrix-org/dendrite/roomserver/storage/sql.go @@ -33,40 +33,20 @@ type statements struct { func (s *statements) prepare(db *sql.DB) error { var err error - if err = s.eventTypeStatements.prepare(db); err != nil { - return err - } - - if err = s.eventStateKeyStatements.prepare(db); err != nil { - return err - } - - if err = s.roomStatements.prepare(db); err != nil { - return err - } - - if err = s.eventStatements.prepare(db); err != nil { - return err - } - - if err = s.eventJSONStatements.prepare(db); err != nil { - return err - } - - if err = s.stateSnapshotStatements.prepare(db); err != nil { - return err - } - - if err = s.stateBlockStatements.prepare(db); err != nil { - return err - } - - if err = s.previousEventStatements.prepare(db); err != nil { - return err - } - - if err = s.roomAliasesStatements.prepare(db); err != nil { - return err + for _, prepare := range []func(db *sql.DB) error{ + s.eventTypeStatements.prepare, + s.eventStateKeyStatements.prepare, + s.roomStatements.prepare, + s.eventStatements.prepare, + s.eventJSONStatements.prepare, + s.stateSnapshotStatements.prepare, + s.stateBlockStatements.prepare, + s.previousEventStatements.prepare, + s.roomAliasesStatements.prepare, + } { + if err = prepare(db); err != nil { + return err + } } return nil