@@ -14,21 +14,26 @@ import (
1414 "unsafe"
1515)
1616
17- type conn struct {
17+ // Conn holds a connection to a DuckDB database.
18+ // It implements the driver.Conn interface.
19+ type Conn struct {
1820 duckdbCon C.duckdb_connection
1921 closed bool
2022 tx bool
2123}
2224
23- func (c * conn ) CheckNamedValue (nv * driver.NamedValue ) error {
25+ // CheckNamedValue implements the driver.NamedValueChecker interface.
26+ func (c * Conn ) CheckNamedValue (nv * driver.NamedValue ) error {
2427 switch nv .Value .(type ) {
2528 case * big.Int , Interval :
2629 return nil
2730 }
2831 return driver .ErrSkip
2932}
3033
31- func (c * conn ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Result , error ) {
34+ // ExecContext executes a query that doesn't return rows, such as an INSERT or UPDATE.
35+ // It implements the driver.ExecerContext interface.
36+ func (c * Conn ) ExecContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Result , error ) {
3237 prepared , err := c .prepareStmts (ctx , query )
3338 if err != nil {
3439 return nil , err
@@ -48,7 +53,9 @@ func (c *conn) ExecContext(ctx context.Context, query string, args []driver.Name
4853 return res , nil
4954}
5055
51- func (c * conn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
56+ // QueryContext executes a query that may return rows, such as a SELECT.
57+ // It implements the driver.QueryerContext interface.
58+ func (c * Conn ) QueryContext (ctx context.Context , query string , args []driver.NamedValue ) (driver.Rows , error ) {
5259 prepared , err := c .prepareStmts (ctx , query )
5360 if err != nil {
5461 return nil , err
@@ -68,11 +75,15 @@ func (c *conn) QueryContext(ctx context.Context, query string, args []driver.Nam
6875 return r , nil
6976}
7077
71- func (c * conn ) PrepareContext (ctx context.Context , query string ) (driver.Stmt , error ) {
78+ // PrepareContext returns a prepared statement, bound to this connection.
79+ // It implements the driver.ConnPrepareContext interface.
80+ func (c * Conn ) PrepareContext (ctx context.Context , query string ) (driver.Stmt , error ) {
7281 return c .prepareStmts (ctx , query )
7382}
7483
75- func (c * conn ) Prepare (query string ) (driver.Stmt , error ) {
84+ // Prepare returns a prepared statement, bound to this connection.
85+ // It implements the driver.Conn interface.
86+ func (c * Conn ) Prepare (query string ) (driver.Stmt , error ) {
7687 if c .closed {
7788 return nil , errors .Join (errPrepare , errClosedCon )
7889 }
@@ -90,11 +101,13 @@ func (c *conn) Prepare(query string) (driver.Stmt, error) {
90101}
91102
92103// Begin is deprecated: Use BeginTx instead.
93- func (c * conn ) Begin () (driver.Tx , error ) {
104+ func (c * Conn ) Begin () (driver.Tx , error ) {
94105 return c .BeginTx (context .Background (), driver.TxOptions {})
95106}
96107
97- func (c * conn ) BeginTx (ctx context.Context , opts driver.TxOptions ) (driver.Tx , error ) {
108+ // BeginTx starts and returns a new transaction.
109+ // It implements the driver.ConnBeginTx interface.
110+ func (c * Conn ) BeginTx (ctx context.Context , opts driver.TxOptions ) (driver.Tx , error ) {
98111 if c .tx {
99112 return nil , errors .Join (errBeginTx , errMultipleTx )
100113 }
@@ -117,7 +130,9 @@ func (c *conn) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, e
117130 return & tx {c }, nil
118131}
119132
120- func (c * conn ) Close () error {
133+ // Close closes the connection to the database.
134+ // It implements the driver.Conn interface.
135+ func (c * Conn ) Close () error {
121136 if c .closed {
122137 return errClosedCon
123138 }
@@ -126,7 +141,7 @@ func (c *conn) Close() error {
126141 return nil
127142}
128143
129- func (c * conn ) extractStmts (query string ) (C.duckdb_extracted_statements , C.idx_t , error ) {
144+ func (c * Conn ) extractStmts (query string ) (C.duckdb_extracted_statements , C.idx_t , error ) {
130145 cQuery := C .CString (query )
131146 defer C .duckdb_free (unsafe .Pointer (cQuery ))
132147
@@ -145,7 +160,7 @@ func (c *conn) extractStmts(query string) (C.duckdb_extracted_statements, C.idx_
145160 return stmts , count , nil
146161}
147162
148- func (c * conn ) prepareExtractedStmt (stmts C.duckdb_extracted_statements , i C.idx_t ) (* stmt , error ) {
163+ func (c * Conn ) prepareExtractedStmt (stmts C.duckdb_extracted_statements , i C.idx_t ) (* Stmt , error ) {
149164 var s C.duckdb_prepared_statement
150165 state := C .duckdb_prepare_extracted_statement (c .duckdbCon , stmts , i , & s )
151166
@@ -155,10 +170,10 @@ func (c *conn) prepareExtractedStmt(stmts C.duckdb_extracted_statements, i C.idx
155170 return nil , err
156171 }
157172
158- return & stmt {c : c , stmt : & s }, nil
173+ return & Stmt {c : c , stmt : & s }, nil
159174}
160175
161- func (c * conn ) prepareStmts (ctx context.Context , query string ) (* stmt , error ) {
176+ func (c * Conn ) prepareStmts (ctx context.Context , query string ) (* Stmt , error ) {
162177 if c .closed {
163178 return nil , errClosedCon
164179 }
0 commit comments