Skip to content

Commit

Permalink
index
Browse files Browse the repository at this point in the history
  • Loading branch information
mattn authored and emidev98 committed Oct 6, 2023
1 parent f89fcc4 commit 17086da
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions storage/sqlite3/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

0 comments on commit 17086da

Please sign in to comment.