66 "path/filepath"
77 "strings"
88
9- "github.com/jmoiron/sqlx"
10-
119 _ "github.com/lib/pq"
1210)
1311
@@ -31,10 +29,10 @@ type PostgresService interface {
3129}
3230
3331type postgresServiceImpl struct {
34- dbConn * sqlx. DB
32+ dbConn * Postgres
3533}
3634
37- func NewPostgresService (dbConn * sqlx. DB ) PostgresService {
35+ func NewPostgresService (dbConn * Postgres ) PostgresService {
3836 p := & postgresServiceImpl {
3937 dbConn : dbConn ,
4038 }
@@ -43,7 +41,7 @@ func NewPostgresService(dbConn *sqlx.DB) PostgresService {
4341
4442func (p * postgresServiceImpl ) Pid () (int , error ) {
4543 var pid int
46- err := p .dbConn .QueryRow ("SELECT pg_backend_pid() AS pid" ).Scan (& pid )
44+ err := p .dbConn .conn . QueryRow ("SELECT pg_backend_pid() AS pid" ).Scan (& pid )
4745 if err != nil {
4846 return 0 , err
4947 }
@@ -52,7 +50,7 @@ func (p *postgresServiceImpl) Pid() (int, error) {
5250
5351func (p * postgresServiceImpl ) Tables () ([]string , error ) {
5452 var tableNames []string
55- err := p .dbConn .Select (& tableNames , "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'" )
53+ err := p .dbConn .conn . Select (& tableNames , "SELECT table_name FROM information_schema.tables WHERE table_schema='public' AND table_type='BASE TABLE'" )
5654 if err != nil {
5755 return nil , err
5856 }
@@ -61,7 +59,7 @@ func (p *postgresServiceImpl) Tables() ([]string, error) {
6159
6260func (p * postgresServiceImpl ) FunctionsDescriptor () ([]string , error ) {
6361 var functions []string
64- err := p .dbConn .Select (& functions , "SELECT routine_name FROM information_schema.routines WHERE routine_catalog = $1 AND routine_schema = 'public' AND routine_type = 'FUNCTION'" , p .Database ())
62+ err := p .dbConn .conn . Select (& functions , "SELECT routine_name FROM information_schema.routines WHERE routine_catalog = $1 AND routine_schema = 'public' AND routine_type = 'FUNCTION'" , p .Database ())
6563 if err != nil {
6664 return nil , err
6765 }
@@ -70,7 +68,7 @@ func (p *postgresServiceImpl) FunctionsDescriptor() ([]string, error) {
7068
7169func (p * postgresServiceImpl ) Database () string {
7270 var database string
73- err := p .dbConn .Get (& database , "SELECT current_database()" )
71+ err := p .dbConn .conn . Get (& database , "SELECT current_database()" )
7472 if err != nil {
7573 panic (err )
7674 }
@@ -79,7 +77,7 @@ func (p *postgresServiceImpl) Database() string {
7977
8078func (p * postgresServiceImpl ) ProceduresDescriptor () ([]string , error ) {
8179 var procedures []string
82- err := p .dbConn .Select (& procedures , "SELECT routine_name FROM information_schema.routines WHERE routine_catalog = $1 AND routine_schema = 'public' AND routine_type = 'PROCEDURE'" , p .Database ())
80+ err := p .dbConn .conn . Select (& procedures , "SELECT routine_name FROM information_schema.routines WHERE routine_catalog = $1 AND routine_schema = 'public' AND routine_type = 'PROCEDURE'" , p .Database ())
8381 if err != nil {
8482 return nil , err
8583 }
@@ -88,7 +86,7 @@ func (p *postgresServiceImpl) ProceduresDescriptor() ([]string, error) {
8886
8987func (p * postgresServiceImpl ) FunctionDDescriptor (function string ) ([]IFunctionDescriptor , error ) {
9088 var functionDetails []IFunctionDescriptor
91- err := p .dbConn .Select (& functionDetails , `
89+ err := p .dbConn .conn . Select (& functionDetails , `
9290 SELECT
9391 r.routine_name,
9492 p.data_type,
@@ -109,7 +107,7 @@ func (p *postgresServiceImpl) FunctionDDescriptor(function string) ([]IFunctionD
109107
110108func (p * postgresServiceImpl ) FunctionReturnType (function string ) (string , error ) {
111109 var returnType string
112- err := p .dbConn .QueryRow ("SELECT pg_get_function_result(oid) FROM pg_proc WHERE proname = $1" , function ).Scan (& returnType )
110+ err := p .dbConn .conn . QueryRow ("SELECT pg_get_function_result(oid) FROM pg_proc WHERE proname = $1" , function ).Scan (& returnType )
113111 if err != nil {
114112 return "" , err
115113 }
@@ -145,7 +143,7 @@ func (p *postgresServiceImpl) AddFunction(function string) (string, error) {
145143
146144func (ps * postgresServiceImpl ) FunctionDescriptor (function string ) (string , error ) {
147145 var functionContent string
148- err := ps .dbConn .QueryRow ("SELECT pg_get_functiondef($1::regproc)" , function ).Scan (& functionContent )
146+ err := ps .dbConn .conn . QueryRow ("SELECT pg_get_functiondef($1::regproc)" , function ).Scan (& functionContent )
149147 if err != nil {
150148 return "" , err
151149 }
@@ -154,15 +152,15 @@ func (ps *postgresServiceImpl) FunctionDescriptor(function string) (string, erro
154152
155153func (p * postgresServiceImpl ) ProcedureDescriptor (procedure string ) (string , error ) {
156154 var procedureContent string
157- err := p .dbConn .QueryRow ("SELECT pg_get_functiondef($1::regproc)" , procedure ).Scan (& procedureContent )
155+ err := p .dbConn .conn . QueryRow ("SELECT pg_get_functiondef($1::regproc)" , procedure ).Scan (& procedureContent )
158156 if err != nil {
159157 return "" , err
160158 }
161159 return procedureContent , nil
162160}
163161
164162func (p * postgresServiceImpl ) ExplainAnalysis (query string ) (string , error ) {
165- rows , err := p .dbConn .Query (fmt .Sprintf ("EXPLAIN ANALYZE %v" , query ))
163+ rows , err := p .dbConn .conn . Query (fmt .Sprintf ("EXPLAIN ANALYZE %v" , query ))
166164 if err != nil {
167165 return "" , err
168166 }
@@ -195,7 +193,7 @@ func (p *postgresServiceImpl) ExecuteBatch(statements []string) error {
195193 if len (statements ) == 0 {
196194 return fmt .Errorf ("missing statements" )
197195 }
198- tx , err := p .dbConn .Beginx ()
196+ tx , err := p .dbConn .conn . Beginx ()
199197 if err != nil {
200198 return err
201199 }
@@ -219,7 +217,7 @@ func (p *postgresServiceImpl) ExecuteBatch(statements []string) error {
219217}
220218
221219func (p * postgresServiceImpl ) ExecuteBatchWithTransaction (statements []string ) error {
222- tx , err := p .dbConn .Beginx ()
220+ tx , err := p .dbConn .conn . Beginx ()
223221 if err != nil {
224222 return err
225223 }
@@ -258,7 +256,7 @@ func (p *postgresServiceImpl) TableDescriptor(table string) ([]ITableDescriptor,
258256 FROM pg_indexes
259257 WHERE tablename = $1;
260258 `
261- rows , err := p .dbConn .Query (s , table )
259+ rows , err := p .dbConn .conn . Query (s , table )
262260 if err != nil {
263261 return nil , err
264262 }
@@ -288,7 +286,7 @@ func (p *postgresServiceImpl) TableInfo(table string) ([]ITableInfo, error) {
288286 WHERE
289287 table_name = $1;
290288 `
291- rows , err := p .dbConn .Query (s , table )
289+ rows , err := p .dbConn .conn . Query (s , table )
292290 if err != nil {
293291 return nil , err
294292 }
0 commit comments