diff --git a/CHANGELOG.md b/CHANGELOG.md index 9749564..5efcd72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning]. ### Changed in 0.5.1 +- + ## [0.5.0] - 2024-08-20 ### Changed in 0.5.0 diff --git a/checker/checker_examples_test.go b/checker/checker_examples_test.go index c07097c..9301b02 100644 --- a/checker/checker_examples_test.go +++ b/checker/checker_examples_test.go @@ -9,12 +9,6 @@ import ( "github.com/senzing-garage/go-databasing/connector" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -23,11 +17,11 @@ func ExampleBasicChecker_IsSchemaInstalled() { // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/checker/checker_examples_test.go ctx := context.TODO() databaseConnector, err := connector.NewConnector(ctx, sqliteDatabaseURL) - printErr(err) - testObject := &BasicChecker{ + failOnError(err) + myChecker := &BasicChecker{ DatabaseConnector: databaseConnector, } - isSchemaInstalled, _ := testObject.IsSchemaInstalled(ctx) + isSchemaInstalled, _ := myChecker.IsSchemaInstalled(ctx) fmt.Printf("isSchemaInstalled: %t", isSchemaInstalled) // Output: isSchemaInstalled: false } @@ -36,11 +30,21 @@ func ExampleBasicChecker_RecordCount() { // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/checker/checker_examples_test.go ctx := context.TODO() databaseConnector, err := connector.NewConnector(ctx, sqliteDatabaseURL) - printErr(err) - testObject := &BasicChecker{ + failOnError(err) + myChecker := &BasicChecker{ DatabaseConnector: databaseConnector, } - recordCount, err := testObject.RecordCount(ctx) - printErr(err) + recordCount, err := myChecker.RecordCount(ctx) + failOnError(err) _ = recordCount // Faux use of recordCount } + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/connector/connector_examples_test.go b/connector/connector_examples_test.go index aea85e8..26c5b7b 100644 --- a/connector/connector_examples_test.go +++ b/connector/connector_examples_test.go @@ -7,22 +7,36 @@ import ( "fmt" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- func ExampleNewConnector_sqlite() { - // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/connectorpostgresql/connectorpostgresql_examples_test.go + // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/connector/connector_examples_test.go ctx := context.TODO() databaseURL := "sqlite3://na:na@$/tmp/sqlite/G2C.db" databaseConnector, err := NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) _ = databaseConnector // Faux use of databaseConnector // Output: } + +func ExampleNewConnector_postgresql() { + // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/connector/connector_examples_test.go + ctx := context.TODO() + databaseURL := "postgresql://postgres:postgres@localhost/G2/?sslmode=disable" + databaseConnector, err := NewConnector(ctx, databaseURL) + failOnError(err) + _ = databaseConnector // Faux use of databaseConnector + // Output: +} + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/connector/doc.go b/connector/doc.go index d5c4ae2..8084980 100644 --- a/connector/doc.go +++ b/connector/doc.go @@ -1,4 +1,6 @@ /* -Package connector returns a "database/sql/driver.Connector" for a given database URL. +Package connector returns a [database/sql/driver.Connector] for a given database URL. + +[database/sql/driver.Connector]: https://pkg.go.dev/database/sql/driver#Connector */ package connector diff --git a/connectormssql/connectormssql.go b/connectormssql/connectormssql.go index e4fd2b1..5900a87 100644 --- a/connectormssql/connectormssql.go +++ b/connectormssql/connectormssql.go @@ -12,12 +12,15 @@ import ( // ---------------------------------------------------------------------------- /* -Function NewConnector is a wrapper for [Microsoft's MSSQL connector]. +Function NewConnector is a wrapper for [Microsoft's MS-SQL connector]. Input - - configuration: See [microsoft/go-mssqldb]. + - dsn: See [microsoft/go-mssqldb]. -[Microsoft's MSSQL connector]: https://pkg.go.dev/github.com/microsoft/go-mssqldb#NewConnector +Output + - [driver.Connector] configured for MS-SQL. + +[Microsoft's MS-SQL connector]: https://pkg.go.dev/github.com/microsoft/go-mssqldb#NewConnector [microsoft/go-mssqldb]: https://github.com/microsoft/go-mssqldb */ func NewConnector(ctx context.Context, dsn string) (driver.Connector, error) { diff --git a/connectormssql/connectormssql_examples_test.go b/connectormssql/connectormssql_examples_test.go index 699954f..8823d1a 100644 --- a/connectormssql/connectormssql_examples_test.go +++ b/connectormssql/connectormssql_examples_test.go @@ -5,22 +5,28 @@ import ( "fmt" ) +// ---------------------------------------------------------------------------- +// Examples for godoc documentation +// ---------------------------------------------------------------------------- + func ExampleNewConnector() { // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/connectormssql/connectormssql_examples_test.go ctx := context.TODO() // See https://github.com/microsoft/go-mssqldb#connection-parameters-and-dsn configuration := "user id=sa;password=Passw0rd;database=master;server=localhost" databaseConnector, err := NewConnector(ctx, configuration) - printErr(err) + failOnError(err) _ = databaseConnector // Faux use of databaseConnector // Output: } +func ExampleNewConnector_null() {} // Hack to format godoc documentation examples properly + // ---------------------------------------------------------------------------- -// non-public functions +// Internal methods // ---------------------------------------------------------------------------- -func printErr(err error) { +func failOnError(err error) { if err != nil { fmt.Println(err) } diff --git a/connectormysql/connectormysql.go b/connectormysql/connectormysql.go index 903637d..afdcf59 100644 --- a/connectormysql/connectormysql.go +++ b/connectormysql/connectormysql.go @@ -12,10 +12,16 @@ import ( // ---------------------------------------------------------------------------- /* -Wrapper for https://pkg.go.dev/github.com/go-sql-driver/mysql#NewConnector +Function NewConnector is a wrapper for [go-sql-driver/mysql]. Input - - configuration: See https://github.com/go-sql-driver/mysql#dsn-data-source-name + - configuration: See [DSN (Data Source Name)]. + +Output + - [driver.Connector] configured for MySQL. + +[DSN (Data Source Name)]: https://github.com/go-sql-driver/mysql#dsn-data-source-name +[go-sql-driver/mysql]: https://pkg.go.dev/github.com/go-sql-driver/mysql#NewConnector */ func NewConnector(ctx context.Context, configuration *mysql.Config) (driver.Connector, error) { _ = ctx diff --git a/connectormysql/connectormysql_examples_test.go b/connectormysql/connectormysql_examples_test.go index 1f470d1..fa9fd56 100644 --- a/connectormysql/connectormysql_examples_test.go +++ b/connectormysql/connectormysql_examples_test.go @@ -9,12 +9,6 @@ import ( "github.com/go-sql-driver/mysql" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -32,7 +26,19 @@ func ExampleNewConnector() { DBName: "G2", } databaseConnector, err := NewConnector(ctx, configuration) - printErr(err) + failOnError(err) _ = databaseConnector // Faux use of databaseConnector // Output: } + +func ExampleNewConnector_null() {} // Hack to format godoc documentation examples properly + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/connectormysql/doc.go b/connectormysql/doc.go index 7bb1b09..090037f 100644 --- a/connectormysql/doc.go +++ b/connectormysql/doc.go @@ -1,4 +1,7 @@ /* -Package connectormysql has ready-made "database/sql/driver.Connector" for "github.com/go-sql-driver/mysql". +Package connectormysql has ready-made [database/sql/driver.Connector] for [github.com/go-sql-driver/mysql]. + +[database/sql/driver.Connector]: https://pkg.go.dev/database/sql/driver#Connector +[github.com/go-sql-driver/mysql]: https://github.com/go-sql-driver/mysql */ package connectormysql diff --git a/connectorpostgresql/connectorpostgresql.go b/connectorpostgresql/connectorpostgresql.go index 8b97c92..0bd73be 100644 --- a/connectorpostgresql/connectorpostgresql.go +++ b/connectorpostgresql/connectorpostgresql.go @@ -12,10 +12,16 @@ import ( // ---------------------------------------------------------------------------- /* -Wrapper for https://pkg.go.dev/github.com/lib/pq#NewConnector +Function NewConnector is a wrapper for [github.com/lib/pq]. Input - - dsn: See https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters + - dsn: See [Connection String Parameters]. + +Output + - [driver.Connector] configured for PostgreSQL. + +[github.com/lib/pq]: https://pkg.go.dev/github.com/lib/pq#NewConnector +[Connection String Parameters]: https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters */ func NewConnector(ctx context.Context, dsn string) (driver.Connector, error) { _ = ctx diff --git a/connectorpostgresql/connectorpostgresql_examples_test.go b/connectorpostgresql/connectorpostgresql_examples_test.go index c6c5e8f..2e2fb53 100644 --- a/connectorpostgresql/connectorpostgresql_examples_test.go +++ b/connectorpostgresql/connectorpostgresql_examples_test.go @@ -5,12 +5,6 @@ import ( "fmt" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -21,7 +15,19 @@ func ExampleNewConnector() { // See https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters configuration := "user=postgres password=postgres dbname=G2 host=localhost sslmode=disable" databaseConnector, err := NewConnector(ctx, configuration) - printErr(err) + failOnError(err) _ = databaseConnector // Faux use of databaseConnector // Output: } + +func ExampleNewConnector_null() {} // Hack to format godoc documentation examples properly + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/connectorpostgresql/doc.go b/connectorpostgresql/doc.go index 9155f57..71fed68 100644 --- a/connectorpostgresql/doc.go +++ b/connectorpostgresql/doc.go @@ -1,4 +1,7 @@ /* -Package connectorpostgresql has ready-made "database/sql/driver.Connector" for "github.com/lib/pq". +Package connectorpostgresql has ready-made [database/sql/driver.Connector] for [github.com/lib/pq]. + +[github.com/lib/pq]: https://github.com/lib/pq +[database/sql/driver.Connector]: https://pkg.go.dev/database/sql/driver#Connector */ package connectorpostgresql diff --git a/connectorsqlite/connectorsqlite.go b/connectorsqlite/connectorsqlite.go index 5637b08..10ba870 100644 --- a/connectorsqlite/connectorsqlite.go +++ b/connectorsqlite/connectorsqlite.go @@ -11,13 +11,13 @@ import ( // Types // ---------------------------------------------------------------------------- -// Connector represents a fixed configuration for the pq driver with a given -// name. Connector satisfies the database/sql/driver Connector interface and -// can be used to create any number of DB Conn's via the database/sql OpenDB -// function. -// -// See https://golang.org/pkg/database/sql/driver/#Connector. -// See https://golang.org/pkg/database/sql/#OpenDB. +/* +Type Sqlite struct implements [driver.Connnector] interface. +This allows Sqlite to be used with [OpenDB]. + +[driver.Connnector]: https://golang.org/pkg/database/sql/driver/#Connector +[OpenDB]: https://golang.org/pkg/database/sql/#OpenDB +*/ type Sqlite struct { Filename string } @@ -26,13 +26,21 @@ type Sqlite struct { // Interface methods // ---------------------------------------------------------------------------- -// Connect returns a connection to the database using the fixed configuration -// of this Connector. Context is not used. +/* +Method Connect implements [driver.Connector]'s Connect method. +Context is not used. + +[driver.Connector]: https://golang.org/pkg/database/sql/driver/#Connector +*/ func (connector *Sqlite) Connect(_ context.Context) (driver.Conn, error) { return connector.Driver().Open(connector.Filename) } -// Driver returns the underlying driver of this Connector. +/* +Method Driver implements [driver.Connector]'s Driver method. + +[driver.Connector]: https://golang.org/pkg/database/sql/driver/#Connector +*/ func (connector *Sqlite) Driver() driver.Driver { return &sqlite.SQLiteDriver{} } @@ -41,6 +49,18 @@ func (connector *Sqlite) Driver() driver.Driver { // Constructor methods // ---------------------------------------------------------------------------- +/* +Function NewConnector is a wrapper for [github.com/mattn/go-sqlite3]. + +Input + - filename: See [github.com/mattn/go-sqlite3]. + +Output + - [driver.Connector] configured for SQLite. + +[github.com/mattn/go-sqlite3]: https://github.com/mattn/go-sqlite3 +[driver.Connector]: https://golang.org/pkg/database/sql/driver/#Connector +*/ func NewConnector(ctx context.Context, filename string) (driver.Connector, error) { _ = ctx return &Sqlite{ diff --git a/connectorsqlite/connectorsqlite_examples_test.go b/connectorsqlite/connectorsqlite_examples_test.go index ec8f4a4..bce5c5e 100644 --- a/connectorsqlite/connectorsqlite_examples_test.go +++ b/connectorsqlite/connectorsqlite_examples_test.go @@ -5,12 +5,6 @@ import ( "fmt" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -20,7 +14,19 @@ func ExampleNewConnector() { ctx := context.TODO() configuration := "/tmp/sqlite/G2C.db" databaseConnector, err := NewConnector(ctx, configuration) - printErr(err) + failOnError(err) _ = databaseConnector // Faux use of databaseConnector // Output: } + +func ExampleNewConnector_null() {} // Hack to format godoc documentation examples properly + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/connectorsqlite/doc.go b/connectorsqlite/doc.go index 30a5a58..4804696 100644 --- a/connectorsqlite/doc.go +++ b/connectorsqlite/doc.go @@ -1,4 +1,7 @@ /* -Package connectorsqlite has ready-made "database/sql/driver.Connector" for "github.com/mattn/go-sqlite3". +Package connectorsqlite has ready-made [database/sql/driver.Connector] for [github.com/mattn/go-sqlite3]. + +[database/sql/driver.Connector]: https://pkg.go.dev/database/sql/driver#Connector +[github.com/mattn/go-sqlite3]: https://github.com/mattn/go-sqlite3 */ package connectorsqlite diff --git a/dbhelper/dbhelper.go b/dbhelper/dbhelper.go index e9e38f1..d11fe7a 100644 --- a/dbhelper/dbhelper.go +++ b/dbhelper/dbhelper.go @@ -8,6 +8,16 @@ import ( "github.com/senzing-garage/go-messaging/messenger" ) +/* +Function ExtractSqliteDatabaseFilename parses an SQLite Database URL +and returns the fully qualified filename. + +Input + - databaseURL: An SQLite style database URL. + +Output + - A fully qualified path to the SQLite database file. +*/ func ExtractSqliteDatabaseFilename(databaseURL string) (string, error) { var result = "" @@ -27,6 +37,22 @@ func ExtractSqliteDatabaseFilename(databaseURL string) (string, error) { return extractSqliteDatabaseFilenameForOsArch(parsedURL) } +/* +Function GetMessenger is a factory to produce a [messenger.Messenger]. + +Input + - componentID: A 4-digit number (0...9999) identifying the component creating the message. + - idMessages: A map of error numbers to messaage templates. + - callerSkip: Number of stack frames to ascend in [runtime.Caller]. + - options: 0 or more [messenger.OptionsXxx]. + +Output + - A configured [messenger.Messenger] implementation. + +[messenger.OptionsXxx]: https://pkg.go.dev/github.com/senzing-garage/go-messaging/messenger#OptionCallerSkip +[runtime.Caller]: https://pkg.go.dev/runtime#Caller +[messenger.Messenger]: https://pkg.go.dev/github.com/senzing-garage/go-messaging/messenger#Messenger +*/ func GetMessenger(componentID int, idMessages map[int]string, callerSkip int, options ...interface{}) messenger.Messenger { optionMessageIDTemplate := fmt.Sprintf("%s%04d", MessageIDPrefix, componentID) + "%04d" messengerOptions := []interface{}{ diff --git a/dbhelper/dbhelper_examples_test.go b/dbhelper/dbhelper_examples_test.go index b7a0aa9..6d35fdf 100644 --- a/dbhelper/dbhelper_examples_test.go +++ b/dbhelper/dbhelper_examples_test.go @@ -4,12 +4,6 @@ package dbhelper import "fmt" -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -18,7 +12,27 @@ func ExampleExtractSqliteDatabaseFilename() { // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/dbhelper/dbhelper_examples_test.go databaseURL := "sqlite3://na:na@/var/opt/senzing/sqlite/G2C.db" databaseFilename, err := ExtractSqliteDatabaseFilename(databaseURL) - printErr(err) + failOnError(err) fmt.Println(databaseFilename) // Output: /var/opt/senzing/sqlite/G2C.db } + +func ExampleGetMessenger() { + // For more information, visit https://github.com/senzing-garage/go-databasing/blob/main/dbhelper/dbhelper_examples_test.go + componentID := 1 + idMessages := map[int]string{} + callerSkip := 0 + options := []interface{}{} + _ = GetMessenger(componentID, idMessages, callerSkip, options...) + // Output: +} + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/dbhelper/doc.go b/dbhelper/doc.go index b112df0..315ea38 100644 --- a/dbhelper/doc.go +++ b/dbhelper/doc.go @@ -1,4 +1,4 @@ /* -Package dbhelper has database agnostic helper functions. +Package dbhelper has database-agnostic helper functions. */ package dbhelper diff --git a/go.mod b/go.mod index cd87d69..70b7699 100644 --- a/go.mod +++ b/go.mod @@ -21,9 +21,9 @@ require ( github.com/golang-sql/sqlexp v0.1.0 // indirect github.com/kr/pretty v0.3.1 // indirect github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect - golang.org/x/crypto v0.26.0 // indirect + golang.org/x/crypto v0.27.0 // indirect golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e // indirect - golang.org/x/net v0.28.0 // indirect + golang.org/x/net v0.29.0 // indirect golang.org/x/sys v0.25.0 // indirect golang.org/x/text v0.18.0 // indirect google.golang.org/genproto/googleapis/rpc v0.0.0-20240903143218-8af14fe29dc1 // indirect diff --git a/go.sum b/go.sum index b20524a..bb800dc 100644 --- a/go.sum +++ b/go.sum @@ -57,12 +57,12 @@ github.com/senzing-garage/go-observing v0.3.3 h1:AhQYgOG012sDZtWXYcXVAaS5qEoDjlW github.com/senzing-garage/go-observing v0.3.3/go.mod h1:qFUi5Dwb6vmd7izTZGjGbWKUGRHzWzsgbsX3oNSD198= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -golang.org/x/crypto v0.26.0 h1:RrRspgV4mU+YwB4FYnuBoKsUapNIL5cohGAmSH3azsw= -golang.org/x/crypto v0.26.0/go.mod h1:GY7jblb9wI+FOo5y8/S2oY4zWP07AkOJ4+jxCqdqn54= +golang.org/x/crypto v0.27.0 h1:GXm2NjJrPaiv/h1tb2UH8QfgC/hOf/+z0p6PT8o1w7A= +golang.org/x/crypto v0.27.0/go.mod h1:1Xngt8kV6Dvbssa53Ziq6Eqn0HqbZi5Z6R0ZpwQzt70= golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e h1:I88y4caeGeuDQxgdoFPUq097j7kNfw6uvuiNxUBfcBk= golang.org/x/exp v0.0.0-20240904232852-e7e105dedf7e/go.mod h1:akd2r19cwCdwSwWeIdzYQGa/EZZyqcOdwWiwj5L5eKQ= -golang.org/x/net v0.28.0 h1:a9JDOJc5GMUJ0+UDqmLT86WiEy7iWyIhz8gz8E4e5hE= -golang.org/x/net v0.28.0/go.mod h1:yqtgsTWOOnlGLG9GFRrK3++bGOUEkNBoHZc8MEDWPNg= +golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo= +golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0= golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34= golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/text v0.18.0 h1:XvMDiNzPAl0jr17s6W9lcaIhGUfUORdGCNsuLmPG224= diff --git a/postgresql/postgresql_basic.go b/postgresql/postgresql_basic.go index 0aa73c1..bd3f0ae 100644 --- a/postgresql/postgresql_basic.go +++ b/postgresql/postgresql_basic.go @@ -19,7 +19,7 @@ import ( // Types // ---------------------------------------------------------------------------- -// BasicPostgresql is the default implementation of the SqlExecutor interface. +// BasicPostgresql is the default implementation of the [Postgresql] interface. type BasicPostgresql struct { DatabaseConnector driver.Connector isTrace bool @@ -45,10 +45,14 @@ var traceOptions = []interface{}{ // ---------------------------------------------------------------------------- /* -The GetCurrentWatermark does a database call for each line scanned. +Method GetCurrentWatermark retrieves information about PostgreSQL's transaction IDs. Input - ctx: A context to control lifecycle. + +Output + - The Object Identifier (oid) + - The age */ func (sqlExecutor *BasicPostgresql) GetCurrentWatermark(ctx context.Context) (string, int, error) { var ( @@ -100,7 +104,7 @@ func (sqlExecutor *BasicPostgresql) GetCurrentWatermark(ctx context.Context) (st } /* -The RegisterObserver method adds the observer to the list of observers notified. +Method RegisterObserver adds the observer to the list of observers notified. Input - ctx: A context to control lifecycle. @@ -131,7 +135,7 @@ func (sqlExecutor *BasicPostgresql) RegisterObserver(ctx context.Context, observ } /* -The SetLogLevel method sets the level of logging. +Method SetLogLevel sets the level of logging. Input - ctx: A context to control lifecycle. @@ -167,7 +171,7 @@ func (sqlExecutor *BasicPostgresql) SetLogLevel(ctx context.Context, logLevelNam } /* -The SetObserverOrigin method sets the "origin" value in future Observer messages. +Method SetObserverOrigin sets the "origin" value in future Observer messages. Input - ctx: A context to control lifecycle. @@ -228,7 +232,7 @@ func (sqlExecutor *BasicPostgresql) SetObserverOrigin(ctx context.Context, origi } /* -The UnregisterObserver method removes the observer to the list of observers notified. +Method UnregisterObserver removes the observer to the list of observers notified. Input - ctx: A context to control lifecycle. diff --git a/postgresql/postgresql_examples_test.go b/postgresql/postgresql_examples_test.go index 8c3e3ea..fd05adc 100644 --- a/postgresql/postgresql_examples_test.go +++ b/postgresql/postgresql_examples_test.go @@ -9,12 +9,6 @@ import ( "github.com/senzing-garage/go-databasing/connectorpostgresql" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -25,13 +19,25 @@ func ExampleBasicPostgresql_GetCurrentWatermark() { // See https://pkg.go.dev/github.com/lib/pq#hdr-Connection_String_Parameters configuration := "user=postgres password=postgres dbname=G2 host=localhost sslmode=disable" databaseConnector, err := connectorpostgresql.NewConnector(ctx, configuration) - printErr(err) + failOnError(err) database := &BasicPostgresql{ DatabaseConnector: databaseConnector, } oid, age, err := database.GetCurrentWatermark(ctx) - printErr(err) + failOnError(err) _ = oid // Faux use of oid _ = age // Faux use of age // Output: } + +func ExampleNewConnector_null() {} // Hack to format godoc documentation examples properly + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +} diff --git a/sqlexecutor/sqlexecutor_basic.go b/sqlexecutor/sqlexecutor_basic.go index d7a9429..dc3388d 100644 --- a/sqlexecutor/sqlexecutor_basic.go +++ b/sqlexecutor/sqlexecutor_basic.go @@ -48,7 +48,7 @@ var traceOptions = []interface{}{ // ---------------------------------------------------------------------------- /* -Method ProcessFileName is a convenience method for calling method [BasicSQLExecutor.ProcessScanner] using a filename. +Method ProcessFileName is a convenience method for calling [BasicSQLExecutor.ProcessScanner] using a filename. Input - ctx: A context to control lifecycle. @@ -174,7 +174,7 @@ func (sqlExecutor *BasicSQLExecutor) ProcessScanner(ctx context.Context, scanner } /* -Method RegisterObserver method adds the observer to the list of observers notified. +Method RegisterObserver adds the observer to the list of observers notified. Input - ctx: A context to control lifecycle. @@ -211,7 +211,7 @@ func (sqlExecutor *BasicSQLExecutor) RegisterObserver(ctx context.Context, obser } /* -Method SetLogLevel method sets the level of logging. +Method SetLogLevel sets the level of logging. Input - ctx: A context to control lifecycle. @@ -247,7 +247,7 @@ func (sqlExecutor *BasicSQLExecutor) SetLogLevel(ctx context.Context, logLevelNa } /* -Method SetObserverOrigin method sets the "origin" value in future Observer messages. +Method SetObserverOrigin sets the "origin" value in future Observer messages. Input - ctx: A context to control lifecycle. @@ -308,7 +308,7 @@ func (sqlExecutor *BasicSQLExecutor) SetObserverOrigin(ctx context.Context, orig } /* -The UnregisterObserver method removes the observer to the list of observers notified. +Method UnregisterObserver removes the observer to the list of observers notified. Input - ctx: A context to control lifecycle. diff --git a/sqlexecutor/sqlexecutor_examples_test.go b/sqlexecutor/sqlexecutor_examples_test.go index ef9b96e..5ae5124 100644 --- a/sqlexecutor/sqlexecutor_examples_test.go +++ b/sqlexecutor/sqlexecutor_examples_test.go @@ -11,12 +11,6 @@ import ( "github.com/senzing-garage/go-databasing/connector" ) -func printErr(err error) { - if err != nil { - fmt.Println(err) - } -} - // ---------------------------------------------------------------------------- // Examples for godoc documentation // ---------------------------------------------------------------------------- @@ -28,12 +22,12 @@ func ExampleBasicSQLExecutor_ProcessFileName_mysql() { databaseURL := "mysql://root:root@localhost:3306/G2" // #nosec G101 sqlFilename := "../testdata/mysql/szcore-schema-mysql-create.sql" databaseConnector, err := connector.NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) sqlExecutor := &BasicSQLExecutor{ DatabaseConnector: databaseConnector, } err = sqlExecutor.ProcessFileName(ctx, sqlFilename) - printErr(err) + failOnError(err) // Output: } @@ -44,12 +38,12 @@ func ExampleBasicSQLExecutor_ProcessFileName_postgresql() { databaseURL := "postgresql://postgres:postgres@localhost:5432/G2/?sslmode=disable" sqlFilename := "../testdata/postgresql/szcore-schema-postgresql-create.sql" databaseConnector, err := connector.NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) sqlExecutor := &BasicSQLExecutor{ DatabaseConnector: databaseConnector, } err = sqlExecutor.ProcessFileName(ctx, sqlFilename) - printErr(err) + failOnError(err) // Output: } @@ -60,12 +54,12 @@ func ExampleBasicSQLExecutor_ProcessFileName_mssql() { databaseURL := "mssql://sa:Passw0rd@localhost:1433/master" sqlFilename := "../testdata/mssql/szcore-schema-mssql-create.sql" databaseConnector, err := connector.NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) sqlExecutor := &BasicSQLExecutor{ DatabaseConnector: databaseConnector, } err = sqlExecutor.ProcessFileName(ctx, sqlFilename) - printErr(err) + failOnError(err) // Output: } @@ -76,14 +70,14 @@ func ExampleBasicSQLExecutor_ProcessFileName_sqlite() { databaseURL := fmt.Sprintf("sqlite3://na:na@%s", databaseFilename) sqlFilename := "../testdata/sqlite/szcore-schema-sqlite-create.sql" err := refreshSqliteDatabase(databaseFilename) // Only needed for repeatable test cases. - printErr(err) + failOnError(err) databaseConnector, err := connector.NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) sqlExecutor := &BasicSQLExecutor{ DatabaseConnector: databaseConnector, } err = sqlExecutor.ProcessFileName(ctx, sqlFilename) - printErr(err) + failOnError(err) // Output: } @@ -94,16 +88,26 @@ func ExampleBasicSQLExecutor_ProcessScanner_sqlite() { databaseURL := fmt.Sprintf("sqlite3://na:na@%s", databaseFilename) sqlFilename := "../testdata/sqlite/szcore-schema-sqlite-create.sql" err := refreshSqliteDatabase(databaseFilename) // Only needed for repeatable test cases. - printErr(err) + failOnError(err) file, err := os.Open(sqlFilename) - printErr(err) + failOnError(err) defer file.Close() databaseConnector, err := connector.NewConnector(ctx, databaseURL) - printErr(err) + failOnError(err) sqlExecutor := &BasicSQLExecutor{ DatabaseConnector: databaseConnector, } err = sqlExecutor.ProcessScanner(ctx, bufio.NewScanner(file)) - printErr(err) + failOnError(err) // Output: } + +// ---------------------------------------------------------------------------- +// Internal methods +// ---------------------------------------------------------------------------- + +func failOnError(err error) { + if err != nil { + fmt.Println(err) + } +}