Przejdź do treści
Biblioteka skilli
Programowanie · Budowanie i kod

sqlc

/sqlc

Dodaje zapytania SQL i generuje kod dla warstwy danych SQLite w projekcie hive, łącznie z mapowaniem typów.

Repozytorium
hive ↗
Licencja
MIT
Ostatnia zmiana repozytorium
25.10.2026

Ocena i bezpieczeństwo

100/ 100Klasa: dobry
Format25 / 25
Frontmatter z nazwą i opisem, poprawna nazwa, opis do 1024 znaków, nazwa zgodna z folderem.
Odkrywalność25 / 25
Opis mówi, kiedy użyć skilla, ma sensowną długość i jest w 3. osobie.
Treść35 / 35
Co najmniej 150 słów i do 500 linii, nagłówki, listy kroków, przykłady albo kod.
Higiena15 / 15
Bez zaślepek typu TODO, bez ścieżek Windows, z licencją.
Ryzykobrak sygnałów w skanie
Pliki w paczce
1
Skrypty
0
Komentarze HTML
0
Adresy URL w SKILL.md
1
Przestarzałość

Brak sygnałów. Repozytorium zmienione 25.10.2026, bez odwołań do wycofanych modeli i API.

Licencja

MIT, otwarta: można używać i zmieniać, z zachowaniem informacji o autorze.

Co robi i kiedy

Dodaje zapytania SQL i generuje kod dla warstwy danych SQLite w projekcie hive, łącznie z mapowaniem typów.

Oryginalny opis (EN)

Add SQL queries, run code generation, and configure type overrides for the hive SQLite data layer. Use when writing new queries, adding tables, or mapping domain types to generated code.

Jak działa

  1. File Layout
  2. Running Code Generation
  3. Adding a Query
  4. Type Overrides (Domain Types in Generated Code)
  5. Schema Source of Truth
  6. Separate Query Files
  7. Common Patterns
Sekcje z nagłówków SKILL.md, w oryginale · 92 linii, 481 słów
Podgląd SKILL.md
---
name: sqlc
description: Add SQL queries, run code generation, and configure type overrides for the hive SQLite data layer. Use when writing new queries, adding tables, or mapping domain types to generated code.
compatibility: claude
---

# sqlc in Hive

Hive uses [sqlc](https://sqlc.dev) to generate type-safe Go from SQL queries. The generated files are committed to the repo — never edit them manually.

## File Layout

```
internal/store/db/
├── queries/
│   ├── queries.sql          # Core session/message queries
│   └── queries_hc.sql       # Honeycomb queries (separate file)
├── migrations/
│   └── NNNN_name.up.sql     # Schema migrations (source of truth for sqlc)
├── queries.sql.go           # Generated — do not edit
├── queries_hc.sql.go        # Generated — do not edit
└── models.go                # Generated — do not edit
```

`sqlc.yaml` at the repo root lists both query files under `sql[0].queries`.

## Running Code Generation

After any change to `.sql` query files or `sqlc.yaml`:

```bash
mise run generate    # runs sqlc generate + go-enum generation
# or directly:
sqlc generate
```

Always commit the generated `*.sql.go` and `models.go` alongside the SQL changes.

## Adding a Query

1. Write the annotated query in the appropriate `.sql` file:

```sql
-- name: GetHCItem :one
SELECT id, repo_key, epic_id, parent_id, session_id, title, "desc",
       type, status, depth, created_at, updated_at
FROM hc_items WHERE id = ?;

-- name: ListHCItems :many
SELECT ... FROM hc_items WHERE repo_key = ? ORDER BY created_at DESC;

-- name: InsertHCItem :exec
INSERT INTO hc_items (...) VALUES (...);
```

Annotations: `:one` (returns single row), `:many` (returns slice), `:exec` (no rows returned).

2. Run `mise run generate`.

3. The generated function appears in `queries_hc.sql.go` (or `queries.sql.go`) under the `db` package.

4. Call it via `s.db.Queries().GetHCItem(ctx, id)`.

## Type Overrides (Domain Types in Generated Code)

When a column stores a domain enum, add an override in `sqlc.yaml` so the generated params/returns use the Go type directly instead of `string`:

```yaml
overrides:
  - column: "hc_items.status"
    go_type:
      import: "github.com/colonyops/hive/internal/domain/hc"
      type: "Status"
  - column: "hc_items.type"
    go_type:
      import: "github.com/colonyops/hive/internal/domain/hc"
      type: "ItemType"
```

The domain type must implement `driver.Valuer` and `sql.Scanner` (or use text marshaling). go-enum generated types satisfy this via `MarshalText`/`UnmarshalText`, which SQLite handles as text.

## Schema Source of Truth

sqlc derives the schema from `internal/store/db/migrations/*.up.sql`. When you add a migration, run `mise run generate` to regenerate models. The generated `models.go` is always overwritten — do not add hand-written code there.

## Separate Query Files

HC queries live in `queries_hc.sql` to keep the diff surface small. Add new feature query files by listing them under `sql[0].queries` in `sqlc.yaml`. All query files share the same `gen.go` output directory and package.

## Common Patterns

**Nullable / optional columns:** Use `sql.NullString`, `sql.NullInt64`, etc. Override with `nullable: true` in `sqlc.yaml` if needed.

**Timestamps:** Stored as `INTEGER NOT NULL` (Unix seconds). The generated code uses `int64`. Conversion to/from `time.Time` happens in the store layer, not in generated code.

**Transactions:** Store methods call queries through `s.db.Ctx(ctx)`, which joins an ambient transaction when the context carries one. Open a unit of work with `s.db.WithinTx(ctx, func(ctx context.Context, q *db.DB) error { ... })`; a nested call joins the outer transaction and only the outermost call commits or rolls back.

Wersje

W bazie nie ma innych skilli o nazwie sqlc.

Migawka bazy z 28.10.2026 · wersja paczki 33b458f55c28 (skrót SHA-256 całej paczki)

Pobrania w ostatnich 30 dniach: 0 · ranking

Zgłoś problem z tym skillem: szkodliwa treść, błędny opis albo prośba autora o usunięcie.

Podobne skille

  • 100db-migration
    Tworzy migracje SQL goose i zapytania sqlc z modelu encji, po czym regeneruje typowany kod dostępu do bazy w Go.
  • 100go-database
    Pomaga pisać, recenzować i debugować kod Go komunikujący się z bazą SQL (PostgreSQL, MySQL, MariaDB, SQLite): wybór biblioteki, zapytania parametryzowane, kontekst, NULL, transakcje, pula połączeń i migracje.
  • 100go-database
    Pomaga pisać, recenzować i debugować kod Go komunikujący się z bazą SQL (PostgreSQL, MySQL, MariaDB, SQLite): wybór biblioteki, zapytania parametryzowane, kontekst, NULL, transakcje, pula połączeń i migracje.
  • 100bun-sqlite
    Obsługuje bun:sqlite: operacje SQLite, przygotowane zapytania, transakcje i zapytania.
  • 100sql-expert
    Pomaga pisać i optymalizować zapytania SQL oraz projektować bazy w PostgreSQL, MySQL, SQLite i BigQuery.
  • 95expo-sqlite
    Obsługuje lokalne dane w aplikacjach Expo i React Native przez expo-sqlite: konfiguracja SQLite, zapytania SQL, migracje schematu, transakcje, SQLiteProvider i kv-store.

Uwagi i zgłoszenia

Wiadomość trafi do Bartosza Sokolińskiego. Adres e-mail jest potrzebny tylko do odpowiedzi. Szczegóły w polityce prywatności.