From 17086da2a2b1d14247f64dc576ffc425f1236878 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Tue, 3 Oct 2023 22:19:56 +0900 Subject: [PATCH] index --- storage/sqlite3/init.go | 33 +++++++++++++++++++++------------ 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/storage/sqlite3/init.go b/storage/sqlite3/init.go index a517345..3810553 100644 --- a/storage/sqlite3/init.go +++ b/storage/sqlite3/init.go @@ -9,6 +9,20 @@ import ( var _ relayer.Storage = (*SQLite3Backend)(nil) +var ddls = []string{ + `CREATE TABLE IF NOT EXISTS event ( + id text NOT NULL, + pubkey text NOT NULL, + created_at integer NOT NULL, + kind integer NOT NULL, + tags jsonb NOT NULL, + content text NOT NULL, + sig text NOT NULL);`, + `CREATE INDEX IF NOT EXISTS idx_event_id on event(id)`, + `CREATE INDEX IF NOT EXISTS idx_event_kind on event(kind)`, + `CREATE INDEX IF NOT EXISTS idx_event_kind_tags on event(kind, tags)`, +} + func (b *SQLite3Backend) Init() error { db, err := sqlx.Connect("sqlite3", b.DatabaseURL) if err != nil { @@ -21,16 +35,11 @@ func (b *SQLite3Backend) Init() error { db.Mapper = reflectx.NewMapperFunc("json", sqlx.NameMapper) b.DB = db - _, err = b.DB.Exec(` -CREATE TABLE IF NOT EXISTS event ( - id text NOT NULL, - pubkey text NOT NULL, - created_at integer NOT NULL, - kind integer NOT NULL, - tags jsonb NOT NULL, - content text NOT NULL, - sig text NOT NULL -); - `) - return err + for _, ddl := range ddls { + _, err = b.DB.Exec(ddl) + if err != nil { + return err + } + } + return nil }