-
Notifications
You must be signed in to change notification settings - Fork 501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add documentation for SetQueryNotification #524
base: master
Are you sure you want to change the base?
Conversation
Codecov Report
@@ Coverage Diff @@
## master #524 +/- ##
==========================================
+ Coverage 68.84% 68.86% +0.01%
==========================================
Files 22 22
Lines 5056 5058 +2
==========================================
+ Hits 3481 3483 +2
Misses 1369 1369
Partials 206 206
Continue to review full report at Codecov.
|
doc/mssql_examples_test.go
Outdated
@@ -0,0 +1,61 @@ | |||
package main |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only documentation (md files) should be in the doc folder. If this example test works as a standalone test, please put it in the root folder.
Since this example is targeting the SetQueryNotification
, you should rename is to something like setquerynotification_example_text.go
.
If you look at other *_examples_test.go files (e.g., datetimeoffset_example_test.go
), you will see that instead of identifying is as package main
, they use package mssql_test
. That way if this file is in the root folder along with the src files, you will not get package clash (having 2 packages in the same directory). When godoc gets this example, they'll replace package mssql_test
with package main
so it looks like a proper test application.
package main | |
package mssql_test |
It's also a good idea to add a .md
file in the doc folder to show the users now this query notification feature works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the function has "Example" prefixing it's name it won't be run as a test. I have moved it from the doc folder though.
doc/mssql_examples_test.go
Outdated
"log" | ||
"time" | ||
|
||
mssql "github.com/denisenkom/go-mssqldb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to explicitly set the alias. It is mssql
by default.
mssql "github.com/denisenkom/go-mssqldb" | |
"github.com/denisenkom/go-mssqldb" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept it since it seems to be like this in other examples.
doc/mssql_examples_test.go
Outdated
server = flag.String("server", "", "the database server") | ||
user = flag.String("user", "", "the database user") | ||
database = flag.String("database", "", "the database name") | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will get redefinition errors here if this file is in package mssql_test
, since these variables are already defined in newconnector_example_test.go
. You can just remove this whole block of variables.
doc/mssql_examples_test.go
Outdated
conn, _ := cn.(*mssql.Conn) | ||
|
||
// Supported SELECT statements: https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms181122(v=sql.105) | ||
stmt, err := conn.Prepare("SELECT [myColumn] FROM [mySchema].[myTable];") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any special setup needed for the Schema and Table for query notification to work? Perhaps add comments letting user know what setup is required?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no special setup for the schema or table but query notifications must be setup on SQL Server for this example to work.
doc/mssql_examples_test.go
Outdated
if err != nil { | ||
log.Fatal("Query failed:", err.Error()) | ||
} else { | ||
rows.Close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does rows
contain in this case? Perhaps add a comment letting user know what is the expected output?
doc/mssql_examples_test.go
Outdated
} else { | ||
rows.Close() | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline.
@chris-rossi and @yukiwongky Thank you for this documentation. Upon examining this feature and how it is used, I would strongly like to alter the current implementation unless I'm totally missing something. Recent I would like to come up with an alternate API for using query notifications that do not involve bypassing the connection pool. First, is it required to set it on a Stmt? In SQL Server, a query batch is first class, not a Stmt. Second, I would like an API like:
|
@kardianos I don't see any reason why this wouldn't work. I think initially they designed it to be set in |
@chris-rossi Then maybe the signature would be:
? |
I presume |
Add Godoc documentation for the SetQueryNotification feature.