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
5
votes
2 answers

sqlc + pgx: array of user defined enum: cannot scan unknown type (OID 16385) in text format

I'm using sqlc and pgx/v5, and getting the below error for a postgres array of a user defined enum type: Error: can't scan into dest[1]: cannot scan unknown type (OID 16385) in text format into *pgtype.Array[my-app/sqlc.Option] schema and…
user2442072
  • 437
  • 2
  • 7
  • 16
5
votes
1 answer

Golang Gin Validation and SQLC

I am using SQLC to generate structures based on my schema and Gin for the web API. After viewing this topic here: Golang how to use Validator with SqlC, I noticed the answer specifically says: I wasn't able to change the Param structs but I guess…
Goodies
  • 4,439
  • 3
  • 31
  • 57
4
votes
1 answer

How to change the text type from pgtype.Text to string in sqlc golang?

I have the generated code for the given query INSERT INTO "users" ( username, name, surname, email, hashed_password, role ) VALUES ( $1, $2, $3, $4, $5, $6 ) RETURNING "id", "username"; which looks like this type…
Mayukh Sarkar
  • 2,289
  • 1
  • 14
  • 38
4
votes
0 answers

How to use gomock with sqlc

I'd like to write unit tests for functions generated by sqlc but I don't understand how to use gomock. I'm new to mocking. Below I'll describe a bit how sqlc generation works. So, sqlc generates an interface DBTX: type DBTX interface { …
3
votes
1 answer

Structuring Nested Data with sqlc, PostgreSQL, and Golang

I am using sqlc with a PostgreSQL database in a Golang project. My database has the following simplified schema: CREATE TABLE users ( username VARCHAR(255) PRIMARY KEY, email VARCHAR(255) UNIQUE NOT NULL ); CREATE TABLE flats ( id SERIAL…
adel
  • 338
  • 1
  • 5
2
votes
1 answer

Nested slice of struct type in sqlc, postgres and golang

I am using sqlc with a PostgreSQL database in a Golang project. My database has the following simplified schema: CREATE TABLE users ( id SERIAL NOT NULL PRIMARY KEY, name TEXT NOT NULL, email TEXT NOT NULL UNIQUE, username TEXT NOT NULL…
zorojuro
  • 21
  • 1
2
votes
1 answer

Is there a way for sqlc to generate code that can use pgxpool

I started using recently sqlc with jackc/pgx/v5. I would like to be able to use pgxpool as well, but there is really no good way to use pgxpool after sqlc takes over in the flow. For instance, this is how I initialize the connection pool: var err…
x80486
  • 6,627
  • 5
  • 52
  • 111
2
votes
1 answer

my data in postgresql is automatically encrypted when creating api with go and sqlc library

I just develop an api to get all field of table of Postgresql. When I use SQL query table 'information_schema.columns' on pgAdmin4 it works (no encryption) as below picture! enter image description here However, I just developed api using go, sqlc…
cyber_g
  • 67
  • 3
2
votes
0 answers

How to get optional output in golang sqlc

I have table which has column with name next_timestamp. And I want next incoming timestamp. For this I wrote below query -- name: GetNextTimestamp :one SELECT MIN(next_timestamp) FROM tableA WHERE next_timestamp > CURRENT_TIMESTAMP; When it…
PSKP
  • 1,178
  • 14
  • 28
2
votes
1 answer

quoted parameters to golang sqlc

using sqlc to generate db methods. Have below query -- name: RemoveRows:exec DELETE FROM demotable WHERE last_updated < (CURRENT_TIMESTAMP - INTERVAL '30' SECOND); I want to pass 30 as parameter but I used below query, then quotes are not coming…
PSKP
  • 1,178
  • 14
  • 28
2
votes
1 answer

Migrating datbase using SQLC from Docker not working

I am trying to generate database migrations using SQLC over Windows OS. According to the official documentation I need to run the Docker command (because it supports Postgres over Windows). If I run docker run --rm -v "${pwd}:/src" -w /src…
Maramal
  • 3,145
  • 9
  • 46
  • 90
2
votes
1 answer

How can I separate generated code package and user code but have them accessible from one place in code

I am newer to golang, so I have some courses that I bought from udemy to help break me into the language. One of them I found very helpful for a general understanding as I took on a project in the language. In the class that I took, all of the sql…
JDev
  • 73
  • 1
  • 8
2
votes
1 answer

'relation "bigint" does not exist' error using sqlc library with go

I'm using the sqlc library to generate go code from SQL queries. I have a query with a subquery like this: COALESCE(SUM(invoice_payments.total), 0) AS paid, And sqlc generate returns the following error: # package db query.sql:101:1: relation…
opensas
  • 60,462
  • 79
  • 252
  • 386
2
votes
0 answers

golang and sqlc, getting pointer issue when generating query

I'm trying to use Golang to call transport data from a Victorian data organisation and store it in a database. I'm using SQLC to try and generate the SQL code to query the database and store the data that is incoming. SQLC is here…
LeCoda
  • 538
  • 7
  • 36
  • 79
2
votes
1 answer

Does Go's sqlc supports join?

I was reading the documentation for SQLC from https://docs.sqlc.dev/en/latest/howto/query_count.html. I wanted to use this in my project. However, I'm not seeing any documentation related to joining operations on the tables. Is it really possible in…
Srikanth Bhandary
  • 1,707
  • 3
  • 19
  • 34
1
2 3