Browse Source

Remove all methods, add Prepare

Volodymyr Tkach 2 years ago
parent
commit
91e182cd39
2 changed files with 11 additions and 2 deletions
  1. 1 0
      gosql/common/common.go
  2. 10 2
      gosql/common/dbmethods.go

+ 1 - 0
gosql/common/common.go

@@ -18,6 +18,7 @@ type Engine interface {
 	Close() error
 	Exec(ctx context.Context, query string, args ...any) (sql.Result, error)
 	Ping(context.Context) error
+	Prepare(ctx context.Context, query string) (*sql.Stmt, error)
 	Query(ctx context.Context, query string, args ...any) (*sql.Rows, error)
 	QueryRow(ctx context.Context, query string, args ...any) *sql.Row
 }

+ 10 - 2
gosql/common/dbmethods.go

@@ -7,7 +7,7 @@ import (
 )
 
 type DBMethods struct {
-	*sql.DB
+	DB *sql.DB
 
 	Driver string
 }
@@ -21,12 +21,20 @@ func (db *DBMethods) fixQuery(query string) string {
 	return query
 }
 
+func (db *DBMethods) Close() error {
+	return db.DB.Close()
+}
+
 func (db *DBMethods) Exec(ctx context.Context, query string, args ...any) (sql.Result, error) {
 	return db.DB.ExecContext(ctx, db.fixQuery(query), args...)
 }
 
 func (db *DBMethods) Ping(ctx context.Context) error {
-	return db.PingContext(ctx)
+	return db.DB.PingContext(ctx)
+}
+
+func (db *DBMethods) Prepare(ctx context.Context, query string) (*sql.Stmt, error) {
+	return db.DB.PrepareContext(ctx, db.fixQuery(query))
 }
 
 func (db *DBMethods) Query(ctx context.Context, query string, args ...any) (*sql.Rows, error) {