Questions tagged [sqlc]

sqlc generates type-safe idiomatic Go code from SQL. Here's how it works:

  • You write queries in SQL
  • You run sqlc to generate code with type-safe interfaces to those queries
  • You write application code that calls the generated code
43 questions
1
vote
0 answers

How to make OFFSET and LIMIT attributes in postgresql query are optional when using SQLC to generate Golang code?

Here is my query statement to be generated. But I want the offset and limit attributes are optional. -- name: ListTransfersTo :many SELECT * FROM transfers WHERE to_account_id = $1 ORDER BY created_at OFFSET $2 LIMIT $3; I try to do following…
1
vote
0 answers

How to deal with uncertain number of input parameters for sqlc query?

Trying to adding a search feature for an existing GO micro service. DB: PostgreSQL. Right now, I am evaluating sqlc as an option. The requirement is to get the result with a single query from multiple tables, so the query will need to join tables.…
wltz
  • 621
  • 1
  • 11
  • 22
1
vote
2 answers

Is it possible to omit field in where clause in postgresql?

In SQL I have following code: -- name: FilterRecords :many SELECT * FROM records WHERE industry_id = $3 and region_code = $4 and city_code = $5 OFFSET $1 LIMIT $2; What I'm trying to achieve is to exclude industry_id from where clause if provided…
Islom
  • 69
  • 8
1
vote
1 answer

How to insert foreign key related items to main table?

I'm trying to reshape/alter table. I have to create a new table and add data from related table column to main table, basically moving data from reference to main. Here is the main table as you can see it has image_pathes array column. CREATE TABLE…
Islom
  • 69
  • 8
1
vote
0 answers

kyleconroy / sqlc - is it possible to handle cross-schema references while generating?

I have two different schemas, and I want to generate SQL that references the other schema in a JOIN statement. However, SQLC throws an error saying "schema not found." This means SQLC doesn't "remember" the schema state from one schema section to…
James
  • 11
  • 1
1
vote
2 answers

getting error while generating gocode with sqlc

sqlc.yaml version: "1" packages: - name: "db" path: "/hcms-backend-go/db/sqlc/" queries: "/hcms-backend-go/db/query/" schema: "/hcms-backend-go/db/migrations/" engine: "postgresql" # If true, add JSON tags to generated structs.…
1
vote
0 answers

Golang sqlc how to auto generate tables based on schema.sql file?

I'm following this tutorial using Golang sqlc with Postgresql, there is an error that says: pq: relation "authors" does not exist exit status 1 whenever I run go run main.go after setting up everything. So the table "authors" is not being generated…
bltz
  • 213
  • 1
  • 4
  • 8
1
vote
1 answer

SQLC Override Bool Type PostgreSQL

I am using SQLC and my YAML config file contains the following type overrides for postgresql: gen: go: emit_json_tags: true package: "hmdb" out: "hmdb" overrides: - db_type: "hstore" nullable: true go_type:…
Goodies
  • 4,439
  • 3
  • 31
  • 57
1
vote
1 answer

sqlc.yaml config isn't going to override postgresql interval to time.Duration

I've found a problem with an sqlc codegen app. In case, when I need an interval (postgresql) field, sqlc generates an object with int64 field. This solution looks broken and creates an error while scanning a row: Errorf("cannot convert %v to…
1
vote
1 answer

pgx copyfrom with WHERE condition

I would like to use pgx (via sqlc) copyfrom feature with a COPY FROM WHERE condition as such: (this condition was taken from a working rule on INSERT): WHERE (EXISTS ( SELECT * FROM asns WHERE merchantId IS NOT…
Reneli
  • 1,756
  • 2
  • 16
  • 26
1
vote
1 answer

SQLC - how to retrieve data stored as JSONB

I have a simple table that has a field JSONB: CREATE TABLE IF NOT EXISTS "test_table" ( "id" text NOT NULL, "user_id" text NOT NULL, "content" jsonb NOT NULL, "create_time" timestamptz NOT NULL, "update_time" timestamptz NOT…
Mido
  • 73
  • 4
1
vote
1 answer

Golang how to use Validator with SqlC

Is there any way to combine the JSON validation [github.com/go-playground/validator/v10] and the JSON Query [sqlc] without having to create two different structs? I have the following table definition CREATE TABLE table1 ( columnName1…
saavedrah
  • 183
  • 14
1
vote
1 answer

Golang with GIN Full Text Search Returning an Empty list

I am trying to make a full text search using Golang with Gin as my router and SQLC for SQL code gen. I get an empty list whether i bind the Query as URI or query. PLease help. type searchProductRequest struct { q string `form:"q"…
pythonGo
  • 125
  • 2
  • 12
1
vote
1 answer

sql.Scan not returning ErrNoRows error when it should

I have a function GetAccount which is generated by sqlc. When I call GetAccount(/*unused id*/), An ErrNoRows error should be returned. Instead I am getting no error and an Account with default values (zeros and empty strings) returned. GetAccount…
SSMSJM
  • 149
  • 6
1
vote
0 answers

How to translate/convert a Postgresql IN query as variable and send the variable using Golang and SQLC with a proper struct?

First of all, if someone has a better sentence for my question, feel free to comment. I want to translate this query into Golang SELECT mou."id", mou."name", mou.description, mou.img_url, um.favorite FROM …