Skip to content

Commit 7c73c9a

Browse files
Merge pull request #5 from oracle-samples/tinglwan-upadte-doc
Update go doc comments
2 parents 894ea83 + cd7b716 commit 7c73c9a

File tree

3 files changed

+29
-26
lines changed

3 files changed

+29
-26
lines changed

oracle/clause_builder.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const (
5858
ClauseReturning = "RETURNING"
5959
)
6060

61+
// Returns the clause builders that are used to generate clauses for Oracle DB
6162
func OracleClauseBuilders() map[string]clause.ClauseBuilder {
6263
return map[string]clause.ClauseBuilder{
6364
ClauseInsert: InsertClauseBuilder,
@@ -70,6 +71,7 @@ func OracleClauseBuilders() map[string]clause.ClauseBuilder {
7071
}
7172
}
7273

74+
// InsertClauseBuilder builds the INSERT INTO cluase
7375
func InsertClauseBuilder(c clause.Clause, builder clause.Builder) {
7476

7577
if insert, ok := c.Expression.(clause.Insert); ok {
@@ -87,6 +89,7 @@ func InsertClauseBuilder(c clause.Clause, builder clause.Builder) {
8789
// Modifier field is intentionally ignored for Oracle
8890
}
8991

92+
// UpdateClauseBuilder builds the UPDATE clause
9093
func UpdateClauseBuilder(c clause.Clause, builder clause.Builder) {
9194
if update, ok := c.Expression.(clause.Update); ok {
9295
builder.WriteString("UPDATE ")
@@ -103,6 +106,7 @@ func UpdateClauseBuilder(c clause.Clause, builder clause.Builder) {
103106
// Modifier field is intentionally ignored for Oracle
104107
}
105108

109+
// DeleteClauseBuilder builds the DELETE clause
106110
func DeleteClauseBuilder(c clause.Clause, builder clause.Builder) {
107111
if _, ok := c.Expression.(clause.Delete); ok {
108112
builder.WriteString("DELETE")
@@ -176,8 +180,8 @@ func ReturningClauseBuilder(c clause.Clause, builder clause.Builder) {
176180
}
177181
}
178182

179-
// getDefaultValues remains the same - it extracts values from sql.Out parameters
180-
183+
// LimitClauseBuilder builds the Oracle FETCH clause instead of using the default LIMIT syntax
184+
// The FETCH syntax is supported in Oracle 12c and later
181185
func LimitClauseBuilder(c clause.Clause, builder clause.Builder) {
182186
if limit, ok := c.Expression.(clause.Limit); ok {
183187
// Convert LIMIT to Oracle FETCH syntax
@@ -187,6 +191,7 @@ func LimitClauseBuilder(c clause.Clause, builder clause.Builder) {
187191
}
188192
}
189193

194+
// ValuesClauseBuilder builds the VALUES clause of an INSERT statement
190195
func ValuesClauseBuilder(c clause.Clause, builder clause.Builder) {
191196
if values, ok := c.Expression.(clause.Values); ok {
192197
if len(values.Columns) > 0 {
@@ -273,7 +278,7 @@ func buildOracleFetchLimit(limit clause.Limit, builder clause.Builder, stmt *gor
273278
}
274279
}
275280

276-
// Updated OnConflictClauseBuilder - builds MERGE statement directly
281+
// OnConflictClauseBuilder builds MERGE statement directly
277282
func OnConflictClauseBuilder(c clause.Clause, builder clause.Builder) {
278283
if onConflict, ok := c.Expression.(clause.OnConflict); ok {
279284
if stmt, ok := builder.(*gorm.Statement); ok {

oracle/migrator.go

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,22 @@ type Migrator struct {
5757
migrator.Migrator
5858
}
5959

60-
// RunWithValue run migration with statement value
60+
// RunWithValue runs migration for the given `value`
6161
func (m Migrator) RunWithValue(value interface{}, fc func(*gorm.Statement) error) error {
6262
if table, ok := value.(string); ok {
6363
return m.Migrator.RunWithValue(table, fc)
6464
}
6565
return m.Migrator.RunWithValue(value, fc)
6666
}
6767

68-
// Database
68+
// CurrentDatabase returns the the name of the current Oracle database
6969
func (m Migrator) CurrentDatabase() string {
7070
var name string
7171
m.DB.Raw("SELECT ora_database_name FROM dual").Scan(&name)
7272
return name
7373
}
7474

75-
// CreateTable create table in database for values
75+
// CreateTable creates table in database for the given `values`
7676
func (m Migrator) CreateTable(values ...interface{}) error {
7777

7878
for _, value := range m.ReorderModels(values, false) {
@@ -201,7 +201,9 @@ func (m Migrator) CreateTable(values ...interface{}) error {
201201
return nil
202202
}
203203

204-
// Drops the table starting from the bottom of the dependency chain
204+
// DropTable drops the table starting from the bottom of the dependency chain.
205+
// The function returns an error when Oracle databases report a missing table.
206+
// If multiple errors occur, it returns a combined (joint) error.
205207
func (m Migrator) DropTable(values ...interface{}) error {
206208
var errorList []error
207209
values = m.ReorderModels(values, false)
@@ -234,7 +236,7 @@ func (m Migrator) HasTable(value interface{}) bool {
234236
return count > 0
235237
}
236238

237-
// RenameTable rename table from oldName to newName
239+
// RenameTable renames table from oldName to newName
238240
func (m Migrator) RenameTable(oldName, newName interface{}) error {
239241
var oldTable, newTable interface{}
240242
if v, ok := oldName.(string); ok {
@@ -259,10 +261,6 @@ func (m Migrator) RenameTable(oldName, newName interface{}) error {
259261
}
260262
}
261263

262-
// TODO: Cannot rename a table that is referenced by a foreign key
263-
// Disable the constraints for each referencing table before renaming,
264-
// and recreate them after renaming
265-
266264
return m.DB.Exec("RENAME ? TO ?", oldTable, newTable).Error
267265
}
268266

@@ -273,8 +271,7 @@ func (m Migrator) GetTables() (tableList []string, err error) {
273271
return
274272
}
275273

276-
// Columns
277-
// AddColumn create `name` column for value
274+
// AddColumn creates `name` column for the given `value`
278275
func (m Migrator) AddColumn(value interface{}, name string) error {
279276
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
280277
// Check if the column name is already used
@@ -290,7 +287,7 @@ func (m Migrator) AddColumn(value interface{}, name string) error {
290287
})
291288
}
292289

293-
// DropColumn drop value's `name` column
290+
// DropColumn drops value's `name` column
294291
func (m Migrator) DropColumn(value interface{}, name string) error {
295292
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
296293
if stmt.Schema != nil {
@@ -307,7 +304,7 @@ func (m Migrator) DropColumn(value interface{}, name string) error {
307304
})
308305
}
309306

310-
// AlterColumn alter value's `field` column's type based on schema definition
307+
// AlterColumn alters value's `field` column's type based on schema definition
311308
func (m Migrator) AlterColumn(value interface{}, field string) error {
312309
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
313310
if stmt.Schema != nil {
@@ -326,7 +323,7 @@ func (m Migrator) AlterColumn(value interface{}, field string) error {
326323
})
327324
}
328325

329-
// HasColumn check has column `field` for value or not
326+
// HasColumn checks whether the table for the given value contains the specified column `field`
330327
func (m Migrator) HasColumn(value interface{}, field string) bool {
331328
var count int64
332329

@@ -340,7 +337,7 @@ func (m Migrator) HasColumn(value interface{}, field string) bool {
340337
return count > 0
341338
}
342339

343-
// ColumnTypes return columnTypes []gorm.ColumnType and execErr error
340+
// ColumnTypes returns the column types for the given value’s table and any error encountered during execution
344341
func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) {
345342
columnTypes := make([]gorm.ColumnType, 0)
346343
execErr := m.RunWithValue(value, func(stmt *gorm.Statement) (err error) {
@@ -370,7 +367,7 @@ func (m Migrator) ColumnTypes(value interface{}) ([]gorm.ColumnType, error) {
370367
return columnTypes, execErr
371368
}
372369

373-
// HasConstraint check has constraint or not
370+
// HasConstraint checks whether the table for the given `value` contains the specified constraint `name`
374371
func (m Migrator) HasConstraint(value interface{}, name string) bool {
375372
var count int64
376373

@@ -389,8 +386,7 @@ func (m Migrator) HasConstraint(value interface{}, name string) bool {
389386
return count > 0
390387
}
391388

392-
// Indexes
393-
// DropIndex drop index `name`
389+
// DropIndex drops the index with the specified `name` from the table associated with `value`
394390
func (m Migrator) DropIndex(value interface{}, name string) error {
395391
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
396392
if stmt.Schema != nil {
@@ -403,7 +399,7 @@ func (m Migrator) DropIndex(value interface{}, name string) error {
403399
})
404400
}
405401

406-
// HasIndex check has index `name` or not
402+
// HasIndex checks whether the table for the given `value` contains an index with the specified `name`
407403
func (m Migrator) HasIndex(value interface{}, name string) bool {
408404
var count int64
409405
m.RunWithValue(value, func(stmt *gorm.Statement) error {
@@ -423,7 +419,7 @@ func (m Migrator) HasIndex(value interface{}, name string) bool {
423419
return count > 0
424420
}
425421

426-
// RenameIndex rename index from oldName to newName
422+
// RenameIndex renames index from oldName to newName on the table for the given `value`
427423
func (m Migrator) RenameIndex(value interface{}, oldName, newName string) error {
428424
return m.RunWithValue(value, func(stmt *gorm.Statement) error {
429425
return m.DB.Exec(
@@ -460,7 +456,7 @@ func (m Migrator) FullDataTypeOf(field *schema.Field) (expr clause.Expr) {
460456
return expr
461457
}
462458

463-
// Build Oracle-compatible default values from string
459+
// Builds Oracle-compatible default values from string
464460
func (m Migrator) buildOracleDefault(defaultValue string) string {
465461
defaultValue = strings.TrimSpace(defaultValue)
466462

oracle/oracle.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,17 @@ type Dialector struct {
7272
*Config
7373
}
7474

75-
// Returns the name of the database dialect
75+
// Name returns the name of the database dialect
7676
func (d Dialector) Name() string {
7777
return "oracle"
7878
}
7979

80+
// Open creates a new godror Dialector with the given DSN
8081
func Open(dsn string) gorm.Dialector {
8182
return &Dialector{Config: &Config{DriverName: "godror", DataSourceName: dsn}}
8283
}
8384

85+
// New creates a new Dialector with the given config
8486
func New(config Config) gorm.Dialector {
8587
return &Dialector{Config: &config}
8688
}
@@ -116,7 +118,7 @@ func (d Dialector) Initialize(db *gorm.DB) (err error) {
116118
return nil
117119
}
118120

119-
// Registers the migrator
121+
// Migrator returns the migrator instance associated with the given gorm.DB
120122
func (d Dialector) Migrator(db *gorm.DB) gorm.Migrator {
121123
return Migrator{
122124
Migrator: migrator.Migrator{

0 commit comments

Comments
 (0)