sqlxqueries

package
v0.19.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 10, 2023 License: AGPL-3.0 Imports: 15 Imported by: 0

README

Editor/IDE config

To edit template files, it is best to configure your IDE to work with go template files. VSCode gives better highlighting support, as the Goland highlighting tends to recognize the sql as invalid and shows many sql errors in the template file.

VSCode

Required extension (Default Golang Extension): https://marketplace.visualstudio.com/items?itemName=golang.Go

The default extension supports syntax highlighting, but requires a configuration change. You must add this section to your golang extension settings:

    "gopls": {
        "ui.semanticTokens": true
    },

The VSCode extension does not support both go template and postgres highlighting. I suggest you use Postgres highlighting, as it is much easier to work with. You can switch between the two with:

  1. ctl + shift + p
  2. "Change language Mode"
  3. "Postgres" or "Go Template File"
  • Feel free to create a permanent file association with *.gosql files.

Goland

Goland supports template highlighting out of the box. To associate sql files, add a new file type in Editor settings. Select "Go template files". Add a new filename of *.gosql and select "postgres" as the "Template Data Language".

Goland language configuration

It also helps to support the sqlc type variables. You can do this by adding "User Parameters" in database queries.

Goland language configuration

You can also add dump.sql as a DDL data source for proper table column recognition.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetContext

func GetContext(ctx context.Context, q sqlx.QueryerContext, queryName string, argument interface{}, res any) error

GetContext runs the named query on the given database. If the query returns no rows, sql.ErrNoRows is returned.

func LoadQueries

func LoadQueries() (*template.Template, error)

LoadQueries parses the embedded queries and returns the template. Results are cached.

func SelectContext

func SelectContext(ctx context.Context, q sqlx.QueryerContext, queryName string, argument any, res any) error

SelectContext runs the named query on the given database. If the query returns no rows, an empty slice is returned.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL