Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
watch_dir nix

use_flake
49 changes: 49 additions & 0 deletions .github/workflows/flake-update.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: "Flake.lock: update Nix dependencies"
on:
workflow_dispatch: # allows manual triggering
schedule:
- cron: "0 0 * * 0" # runs weekly on Sunday at 00:00
jobs:
nix-flake-update:
permissions:
contents: write
id-token: write
issues: write
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
with:
token: ${{ secrets.GHA_PAT_TOKEN }}
- uses: cachix/install-nix-action@v31
- uses: cachix/cachix-action@v16
with:
name: kalbasit
authToken: ${{ secrets.CACHIX_AUTH_TOKEN }}
- name: update flake.lock and run go mod tidy
id: update-flake-lock-and-go-mod-tidy
run: |
nix flake update
nix develop --command go mod tidy
- uses: EndBug/add-and-commit@v9
if: ${{ steps.update-flake-lock-and-go-mod-tidy.outcome == 'success' }}
id: commit
with:
default_author: github_actions
message: "chore: update flake.lock and run go mod tidy"
fetch: false
new_branch: "update-flake-lock"
push: --set-upstream origin "update-flake-lock" --force
- uses: thomaseizinger/create-pull-request@1.4.0
if: ${{ steps.commit.outputs.pushed == 'true' }}
id: create_pr
with:
github_token: ${{ secrets.GHA_PAT_TOKEN }}
head: "update-flake-lock"
base: main
title: "chore: update flake.lock and run go mod tidy"
- name: enable automerge
if: ${{ steps.create_pr.outputs.created }}
run: gh pr merge --squash --auto "${{ steps.create_pr.outputs.number }}"
env:
GH_TOKEN: "${{ secrets.GHA_PAT_TOKEN }}"
48 changes: 48 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# If you prefer the allow list template instead of the deny list, see community template:
# https://github.com/github/gitignore/blob/main/community/Golang/Go.AllowList.gitignore
#
# Binaries for programs and plugins
*.exe
*.exe~
*.dll
*.so
*.dylib

# Test binary, built with `go test -c`
*.test

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

# Dependency directories (remove the comment below to include it)
# vendor/

# Editor files
/.vscode/**
!/.vscode/settings.json
!/.vscode/tasks.json
!/.vscode/launch.json
!/.vscode/extensions.json

# Go workspace file
go.work
go.work.sum

# env file used by dbmate
.env

# Go and Nix-related build result
/ncps
/result*
/.direnv

# Pre-commit configuration (auto-generated)
/.pre-commit-config.yaml

# Python Cache
__pycache__/
*.pyc
*.pyo

# Agents
/.claude/settings.local.json
70 changes: 70 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: "2"
formatters:
enable:
- gci
- gofumpt
settings:
gci:
sections:
- standard
- default
- alias
- prefix(github.com/kalbasit/sqlc-multi-db)
- blank
- dot
custom-order: true
exclusions:
generated: lax
linters:
enable:
- err113
- errname
- exhaustive
- gochecknoglobals
- gochecknoinits
- goconst
- godot
- goheader
- gosec
- importas
- lll
- makezero
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nlreturn
- noctx
- nolintlint
- paralleltest
- prealloc
- predeclared
- revive
- rowserrcheck
- staticcheck
- tagliatelle
- testifylint
- testpackage
- unconvert
- unparam
- wastedassign
- whitespace
- wsl_v5
- zerologlint
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
rules:
- path: generator/templates\.go
linters:
- lll
settings:
wsl_v5:
allow-first-in-block: true
allow-whole-block: false
branch-max-lines: 2
129 changes: 129 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
description = "TODO";

inputs = {

flake-parts = {
inputs.nixpkgs-lib.follows = "nixpkgs";
url = "github:hercules-ci/flake-parts";
};

git-hooks-nix = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:cachix/git-hooks.nix";
};

nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.11";

treefmt-nix = {
inputs.nixpkgs.follows = "nixpkgs";
url = "github:numtide/treefmt-nix";
};

};

outputs =
inputs@{ flake-parts, ... }:
flake-parts.lib.mkFlake { inherit inputs; } {
imports = [
./nix/devshells/flake-module.nix
./nix/formatter/flake-module.nix
./nix/pre-commit/flake-module.nix
];
systems = [
"x86_64-linux"
"aarch64-linux"
"aarch64-darwin"
"x86_64-darwin"
];
};
}
23 changes: 23 additions & 0 deletions generator/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package generator

const (
typeQuerier = "Querier"
typeAny = "interface{}"
typeBool = "bool"
typeString = "string"
zeroNil = "nil"
typeInt16 = "int16"
typeInt32 = "int32"
typeInt64 = "int64"
typeFloat64 = "float64"
typeByte = "byte"

sqlNullString = "sql.NullString"
sqlNullInt64 = "sql.NullInt64"
sqlNullInt32 = "sql.NullInt32"
sqlNullInt16 = "sql.NullInt16"
sqlNullBool = "sql.NullBool"
sqlNullFloat64 = "sql.NullFloat64"
sqlNullTime = "sql.NullTime"
sqlNullByte = "sql.NullByte"
)
21 changes: 21 additions & 0 deletions generator/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package generator

import (
"errors"
"fmt"
)

var (
errInvalidDictCall = errors.New("invalid dict call")
errDictKeysMustBeStrings = errors.New("dict keys must be strings")

errSliceDomainStructNotSupported = errors.New(
"slices of domain structs are not supported as direct parameters, as they require a conversion loop" +
" to be generated. The auto-looping for bulk inserts handles this by operating on a struct" +
" parameter containing a slice",
)
)

func errUnsupportedSliceDomainStruct(t string) error {
return fmt.Errorf("unsupported parameter type: slice of domain struct %s: %w", t, errSliceDomainStructNotSupported)
}
Loading