Code Monkey home page Code Monkey logo

Comments (2)

bldrdash avatar bldrdash commented on June 25, 2024 1

@StevenACoffman I came here looking for the same thing.

You can get these annotations by modifying the sqlc-gen-go template in internal/templates/./queryCode.tmpl.

That said, you didn't want to use the database/sql interface and I was unable to get prashanthpai/sqlcache to work using pgx/pgxpool directly. But that looks like a limitation of prashanthpai/sqlcache

I was able to get this to work by modifying the template in internal/templates/stdlib/queryCode.tmpl like so:

...
const {{.ConstantName}} = {{$.Q}}-- name: {{.MethodName}} {{.Cmd}}
{{range .Comments}}--{{.}}
{{end -}}
{{escape .SQL}}
{{$.Q}}
...

You can then write your query as:

-- name: ProductByZip :many
-- @cache-ttl 30
-- @cache-max-rows 100
select distinct p.name as product, v.name as vendor from product p
join vendors v on p.vendor = v.id
join vendorsa va on v.id = va.vendor
where va.zip = $1;

Hope this helps.

from sqlc.

StevenACoffman avatar StevenACoffman commented on June 25, 2024

@bldrdash Nice!

I filed an issue with jackc/pgx#1935 along the same lines, and the maintainer raised a good point.

The declarative nature of prashanthpai/sqlcache is nice, but the way sqlcache (and sqlmw) is implemented in the SQL driver, it requires a re-parse before deciding to just use the cached version. This makes the performance worse than it needs to be.

If the sqlc generated template Go code decided to attempt to use the cached version, it would not require re-parsing the SQL, so it would perform faster.

from sqlc.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.