mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-09-19 09:40:12 +00:00
feat(agentcompat): add SQLite hold scoped attribution
Co-authored-by: naiba/CloudCode <hi+cloudcode@nai.ba>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
//go:build agentcompat && linux
|
||||
|
||||
package singleton
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
)
|
||||
|
||||
func (connection *sqliteAttributionConnection) Exec(query string, values []driver.Value) (driver.Result, error) {
|
||||
statement, err := connection.Prepare(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer statement.Close()
|
||||
return statement.Exec(values)
|
||||
}
|
||||
|
||||
func (connection *sqliteAttributionConnection) ExecContext(ctx context.Context, query string, values []driver.NamedValue) (driver.Result, error) {
|
||||
statement, err := connection.PrepareContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer statement.Close()
|
||||
return statement.(driver.StmtExecContext).ExecContext(ctx, values)
|
||||
}
|
||||
|
||||
func (connection *sqliteAttributionConnection) Query(query string, values []driver.Value) (driver.Rows, error) {
|
||||
statement, err := connection.Prepare(query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
wrapped := statement.(*sqliteAttributionStatement)
|
||||
return wrapped.queryOwned(func() (driver.Rows, error) { return wrapped.statement.Query(values) }, statement)
|
||||
}
|
||||
|
||||
func (connection *sqliteAttributionConnection) QueryContext(ctx context.Context, query string, values []driver.NamedValue) (driver.Rows, error) {
|
||||
statement, err := connection.PrepareContext(ctx, query)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return connection.queryContextStatement(ctx, statement.(*sqliteAttributionStatement), values, statement)
|
||||
}
|
||||
|
||||
func (connection *sqliteAttributionConnection) queryContextStatement(ctx context.Context, statement *sqliteAttributionStatement, values []driver.NamedValue, owner driver.Stmt) (driver.Rows, error) {
|
||||
contextStatement, ok := statement.statement.(driver.StmtQueryContext)
|
||||
if !ok {
|
||||
return nil, errors.Join(driver.ErrSkip, owner.Close())
|
||||
}
|
||||
return statement.queryOwned(func() (driver.Rows, error) { return contextStatement.QueryContext(ctx, values) }, owner)
|
||||
}
|
||||
Reference in New Issue
Block a user