mirror of
https://github.com/fiatjaf/khatru.git
synced 2025-03-27 10:12:54 +01:00
32 lines
566 B
Go
32 lines
566 B
Go
// +build !lite
|
|
|
|
package main
|
|
|
|
import (
|
|
"github.com/jmoiron/sqlx"
|
|
_ "github.com/mattn/go-sqlite3"
|
|
)
|
|
|
|
func initDB() (*sqlx.DB, error) {
|
|
db, err := sqlx.Connect("sqlite3", s.SQLiteDatabase)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
_, err = db.Exec(`
|
|
CREATE TABLE event (
|
|
id text NOT NULL,
|
|
pubkey text NOT NULL,
|
|
created_at integer NOT NULL,
|
|
kind integer NOT NULL,
|
|
tags text NOT NULL,
|
|
content text NOT NULL,
|
|
sig text NOT NULL
|
|
);
|
|
|
|
CREATE UNIQUE INDEX ididx ON event (id);
|
|
CREATE INDEX pubkeytimeidx ON event (pubkey, created_at);
|
|
`)
|
|
return db, nil
|
|
}
|