Skip to content

Commit

Permalink
revert unrelated import string prefix change, and add pgx tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewmbenton committed Jun 20, 2023
1 parent a007565 commit 2647552
Show file tree
Hide file tree
Showing 11 changed files with 228 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/codegen/golang/imports.go
Original file line number Diff line number Diff line change
Expand Up @@ -460,9 +460,15 @@ func (i *importer) batchImports() fileImports {
return sortedImports(std, pkg)
}

func trimSliceAndPointerPrefix(v string) string {
v = strings.TrimPrefix(v, "[]")
v = strings.TrimPrefix(v, "*")
return v
}

func hasPrefixIgnoringSliceAndPointerPrefix(s, prefix string) bool {
trimmedS := strings.TrimLeft(s, "*[]")
trimmedPrefix := strings.TrimLeft(prefix, "*[]")
trimmedS := trimSliceAndPointerPrefix(s)
trimmedPrefix := trimSliceAndPointerPrefix(prefix)
return strings.HasPrefix(trimmedS, trimmedPrefix)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Example queries for sqlc
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text,
tags string[]
);

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2",
"sql": [{
"schema": "query.sql",
"queries": "query.sql",
"engine": "postgresql",
"gen": {
"go": {
"sql_package": "pgx/v4",
"package": "query",
"out": "query",
"overrides": [{
"column": "authors.tags",
"go_type": {
"type": "NullInt64",
"import": "database/sql",
"slice": true
}
}]
}
}
}]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
-- Example queries for sqlc
CREATE TABLE authors (
id BIGSERIAL PRIMARY KEY,
name text NOT NULL,
bio text,
tags string[]
);

-- name: GetAuthor :one
SELECT * FROM authors
WHERE id = $1 LIMIT 1;

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2",
"sql": [{
"schema": "query.sql",
"queries": "query.sql",
"engine": "postgresql",
"gen": {
"go": {
"sql_package": "pgx/v5",
"package": "query",
"out": "query",
"overrides": [{
"column": "authors.tags",
"go_type": {
"type": "NullInt64",
"import": "database/sql",
"slice": true
}
}]
}
}
}]
}

0 comments on commit 2647552

Please sign in to comment.