Skip to content

Conversation

@kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Jul 29, 2020

Fix a number of bugs when resolving function calls.
Switch to using functions generated from a default PostgreSQL instance.
Add a new test case ripped from the PostgreSQL docs.

I've noted the improvements in individual comments

Fix a number of bugs when resolving function calls.
Switch to using functions generated from a default PostgreSQL instance.
Add a new test case ripped from the PostgreSQL docs.
`

func (q *Queries) MakeIntervalDays(ctx context.Context, dollar_1 int32) (interface{}, error) {
func (q *Queries) MakeIntervalDays(ctx context.Context, dollar_1 int32) (int64, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make_interval now returns an actual type instead of interface{}. This happened because we can now resolve function calls with defaults and named parameters.

`

func (q *Queries) MakeIntervalSecs(ctx context.Context, secs interface{}) (interface{}, error) {
func (q *Queries) MakeIntervalSecs(ctx context.Context, secs float64) (int64, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The compiler is now smart enough to pull out type information for named parameters in function calls.


func (q *Queries) Plus(ctx context.Context, arg PlusParams) (int32, error) {
row := q.db.QueryRowContext(ctx, plus, arg.B, arg.A)
row := q.db.QueryRowContext(ctx, plus, arg.A, arg.B)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!!!

The compiler generated incorrect code here. The order of the arguments wasn't correct.

}

func (q *Queries) GenerateSeries(ctx context.Context, arg GenerateSeriesParams) ([]interface{}, error) {
func (q *Queries) GenerateSeries(ctx context.Context, arg GenerateSeriesParams) ([]string, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Goodbye interface{}! Real return values for function calls


func (q *Queries) AdvisoryLock(ctx context.Context, key int64) ([]bool, error) {
rows, err := q.db.QueryContext(ctx, advisoryLock, key)
func (q *Queries) AdvisoryLock(ctx context.Context, pgAdvisoryUnlock int64) ([]bool, error) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While the PostgreSQL documentation claims the first parameter to pg_advisory_unlock is named key, that name isn't actually included in the definition of the function stored in the database.

c := catalog.New("public")
c.Schemas = append(c.Schemas, pgTemp())
c.Schemas = append(c.Schemas, pgCatalog())
c.Schemas = append(c.Schemas, genPGCatalog())
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit scary! I'm curious if we'll have to walk this specific change back.

@kyleconroy kyleconroy merged commit d2541ce into master Jul 29, 2020
@kyleconroy kyleconroy deleted the calling-funcs branch July 29, 2020 17:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants