Initial commit: email-openclaw bridge v1
Full pipeline: IMAP ingress -> OpenClaw dispatch -> callback -> SMTP reply. SQLite stateful storage with idempotency, threading, and retry logic. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package database
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/glebarez/sqlite"
|
||||
"gorm.io/gorm"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
|
||||
// Open initializes the SQLite database and runs auto-migration.
|
||||
func Open(dbPath string) (*gorm.DB, error) {
|
||||
db, err := gorm.Open(sqlite.Open(dbPath), &gorm.Config{
|
||||
Logger: logger.Default.LogMode(logger.Silent), // We use our own structured logger.
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("database open: %w", err)
|
||||
}
|
||||
|
||||
// Enable WAL mode for better concurrent read performance.
|
||||
if err := db.Exec("PRAGMA journal_mode=WAL").Error; err != nil {
|
||||
return nil, fmt.Errorf("database pragma WAL: %w", err)
|
||||
}
|
||||
|
||||
if err := db.AutoMigrate(&Task{}); err != nil {
|
||||
return nil, fmt.Errorf("database migrate: %w", err)
|
||||
}
|
||||
|
||||
return db, nil
|
||||
}
|
||||
|
||||
// Healthy checks if the database is writable.
|
||||
func Healthy(db *gorm.DB) error {
|
||||
return db.Exec("SELECT 1").Error
|
||||
}
|
||||
Reference in New Issue
Block a user