3

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

  • Connection hooks are specific to the connection, so won't be triggered by updates to other connections, whether they're in the same or an external process. Can you explain what you need to do in more detail? – Mark Jun 02 '20 at 05:18

0 Answers0