Closed
Description
Version
1.15.0
What happened?
-- name: UpdateChapter :one
UPDATE chapters
SET name = coalesce(sqlc.narg('name'), name),
content = coalesce(sqlc.narg('content'), content)
WHERE id = sqlc.arg('id')
RETURNING *;
It does not work.
Relevant log output
$ sqlc generate
line 26:29 no viable alternative at input ';\n\n-- name: UpdateChapter :one\nUPDATE chapters\nSET name = coalesce(sqlc.narg('
line 26:29 no viable alternative at input 'UPDATE chapters\nSET name = coalesce(sqlc.narg('
# package main
D:\Fang\repos\gobook\db\queries\chapters.sql:1:1: no viable alternative at input 'UPDATE chapters\nSET name = coalesce(sqlc.narg('
Database schema
CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name text NOT NULL,
author text,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
CREATE TABLE IF NOT EXISTS chapters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name text NOT NULL,
book_id INTEGER NOT NULL,
content text,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE books ADD summary text;
ALTER TABLE books ADD deleted_at DATETIME;
CREATE TABLE IF NOT EXISTS chapters (
id INTEGER PRIMARY KEY AUTOINCREMENT,
book_id INTEGER NOT NULL,
name TEXT NOT NULL,
content TEXT NOT NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
deleted_at DATETIME
);
ALTER TABLE chapters
ADD COLUMN parent_id
INTEGER DEFAULT 0
NOT NULL;
ALTER TABLE chapters
ADD COLUMN deleted_at DATETIME;
SQL queries
-- name: ListChapters :many
SELECT * FROM chapters
WHERE book_id = ?
AND deleted_at IS NULL
ORDER BY id;
-- name: CreateChapter :one
INSERT INTO chapters (
book_id,
name,
content
) VALUES (
?,
?,
?
)
RETURNING *;
-- name: DeleteChapter :exec
UPDATE chapters
SET deleted_at = date('now')
WHERE id = ?;
-- name: UpdateChapter :one
UPDATE chapters
SET name = coalesce(sqlc.narg('name'), name),
content = coalesce(sqlc.narg('content'), content)
WHERE id = sqlc.arg('id')
RETURNING *;
Configuration
version: 2
sql:
- engine: "sqlite"
schema:
- "db/schema.sql"
- "db/migrations/"
queries:
- "db/queries"
gen:
go:
package: "main"
out: "."
emit_json_tags: true
overrides:
- db_type: "text"
go_type:
type: "string"
pointer: true
nullable: true
- db_type: "INTEGER"
go_type:
type: "int64"
pointer: false
nullable: false
- db_type: "INTEGER"
go_type:
type: "int64"
pointer: true
nullable: true
- db_type: "DATE"
go_type:
import: "time"
type: "Time"
pointer: true
nullable: true
- db_type: "DATETIME"
go_type:
import: "time"
type: "Time"
pointer: true
nullable: true
- db_type: "TIMESTAMP"
go_type:
import: "time"
type: "Time"
pointer: true
nullable: true
Playground URL
No response
What operating system are you using?
Windows
What database engines are you using?
PostgreSQL
What type of code are you generating?
Go