-
Notifications
You must be signed in to change notification settings - Fork 555
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
feat: add dialect for spanner using pg adapter #900
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
//go:build !no_spannerpg | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wasn't sure about this file, since Spanner PG would use the regular Postgres PGX driver, so should we just use "no_postgres" for both postgres and spanner? |
||
// +build !no_spannerpg | ||
|
||
package main | ||
|
||
//Spanner using PG (postgres) adapter. Using pgx as a driver. | ||
import ( | ||
_ "github.com/jackc/pgx/v5/stdlib" | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package dialectquery | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Spanner via PGAdapter only has partial support for |
||
|
||
import ( | ||
"fmt" | ||
) | ||
|
||
type SpannerPG struct{} | ||
|
||
var _ Querier = (*SpannerPG)(nil) | ||
|
||
func (p *SpannerPG) CreateTable(tableName string) string { | ||
q := `CREATE TABLE %s ( | ||
id bigint PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY (BIT_REVERSED_POSITIVE), | ||
version_id bigint NOT NULL, | ||
is_applied boolean NOT NULL, | ||
tstamp timestamptz NOT NULL DEFAULT now() | ||
)` | ||
return fmt.Sprintf(q, tableName) | ||
} | ||
|
||
func (p *SpannerPG) InsertVersion(tableName string) string { | ||
q := `INSERT INTO %s (version_id, is_applied) VALUES ($1, $2)` | ||
return fmt.Sprintf(q, tableName) | ||
} | ||
|
||
func (p *SpannerPG) DeleteVersion(tableName string) string { | ||
q := `DELETE FROM %s WHERE version_id=$1` | ||
return fmt.Sprintf(q, tableName) | ||
} | ||
|
||
func (p *SpannerPG) GetMigrationByVersion(tableName string) string { | ||
q := `SELECT tstamp, is_applied FROM %s WHERE version_id=$1 ORDER BY tstamp DESC LIMIT 1` | ||
return fmt.Sprintf(q, tableName) | ||
} | ||
|
||
func (p *SpannerPG) ListMigrations(tableName string) string { | ||
q := `SELECT version_id, is_applied from %s ORDER BY id DESC` | ||
return fmt.Sprintf(q, tableName) | ||
} | ||
|
||
func (p *SpannerPG) GetLatestVersion(tableName string) string { | ||
q := `SELECT max(version_id) FROM %s` | ||
return fmt.Sprintf(q, tableName) | ||
} |
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.
This assume the PGAdapter is running locally on the default postgres port.