Reputation: 31
everybody. I use the library "github.com/mattn/go-sqlite3" for working with the database. I need to track the changes made to the database and after these changes are complete, execute some code. I need to track the changes that another process makes to this database.. For example, there is a Products table with the name and id fields I want to get a notification after the name field has been changed
How can I do this? any solution Thanks
sqlite3conn := []*sqlite3.SQLiteConn{}
sql.Register("sqlite3_with_hook_example",
&sqlite3.SQLiteDriver{
ConnectHook: func(conn *sqlite3.SQLiteConn) error {
sqlite3conn = append(sqlite3conn, conn)
conn.RegisterUpdateHook(func(op int, db string, table string, rowid int64) {
switch op {
case sqlite3.SQLITE_INSERT:
log.Println("Notified of insert on db - ", db, "table:", table, "rowid:", rowid)
}
})
return nil
},
})
This code only tracks the changes that the Go script makes, if I make an insert from the console, it doesn't work
Upvotes: 3
Views: 801