Skip to content

feat: Add the diff command #1963

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

Merged
merged 3 commits into from
Nov 22, 2022
Merged

feat: Add the diff command #1963

merged 3 commits into from
Nov 22, 2022

Conversation

kyleconroy
Copy link
Collaborator

@kyleconroy kyleconroy commented Nov 22, 2022

Add a diff command to easily check if sqlc generate has been run. The idea is to run this as part of your continuous integration workflow to verify that your generated code is always up to date. This won't work if you manually edit the contents of generated files.

Sample output

--- a/go/models.go
+++ b/go/models.go
@@ -13,3 +13,8 @@
 	Name string
 	Bio  sql.NullString
 }
+
+type Book struct {
+	ID    int64
+	Title string
+}
--- a/go/query.sql.go
+++ b/go/query.sql.go
@@ -31,16 +31,6 @@
 	return i, err
 }
 
-const deleteAuthor = `-- name: DeleteAuthor :exec
-DELETE FROM authors
-WHERE id = $1
-`
-
-func (q *Queries) DeleteAuthor(ctx context.Context, id int64) error {
-	_, err := q.db.ExecContext(ctx, deleteAuthor, id)
-	return err
-}
-
 const getAuthor = `-- name: GetAuthor :one
 SELECT id, name, bio FROM authors
 WHERE id = $1 LIMIT 1
@@ -55,7 +45,7 @@
 
 const listAuthors = `-- name: ListAuthors :many
 SELECT id, name, bio FROM authors
+ORDER BY bio
-ORDER BY name
 `
 
 func (q *Queries) ListAuthors(ctx context.Context) ([]Author, error) {
@@ -80,3 +70,14 @@
 	}
 	return items, nil
 }
+
+const selectOne = `-- name: SelectOne :one
+SELECT 1
+`
+
+func (q *Queries) SelectOne(ctx context.Context) (interface{}, error) {
+	row := q.db.QueryRowContext(ctx, selectOne)
+	var column_1 interface{}
+	err := row.Scan(&column_1)
+	return column_1, err
+}

@kyleconroy kyleconroy added this to the v1.17.0 milestone Nov 22, 2022
@kyleconroy kyleconroy merged commit f5c1a5e into main Nov 22, 2022
@kyleconroy kyleconroy deleted the kyle/diff branch November 22, 2022 09:19
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.

1 participant