Skip to content

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.

2 participants