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
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
SOURCE_WASM_FILE_UBUNTU="WasmRunner/obj/release/net8.0/wasi-wasm/wasm/for-publish/WasmRunner.wasm"
SOURCE_WASM_FILE="WasmRunner/bin/Release/net8.0/wasi-wasm/AppBundle/WasmRunner.wasm"
SOURCE_WASM_FILE_UBUNTU="WasmRunner/obj/release/net10.0/wasi-wasm/wasm/for-publish/WasmRunner.wasm"
SOURCE_WASM_FILE="WasmRunner/obj/release/net10.0/wasi-wasm/wasm/for-publish/WasmRunner.wasm"

SQLITE_CONNECTION_STRING="Data Source=tests.db;Mode=ReadWrite"
MYSQL_CONNECTION_STRING="server=localhost;database=tests;user=root;AllowLoadLocalInfile=true;ConvertZeroDateTime=True"
Expand Down
15 changes: 6 additions & 9 deletions .github/workflows/benchmark.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ permissions:
contents: write
pull-requests: write

env:
DOTNET_VERSION: '8.0.x'

on:
release:
types: [ published ]
Expand All @@ -29,7 +26,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down Expand Up @@ -65,7 +62,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down Expand Up @@ -101,7 +98,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down Expand Up @@ -137,7 +134,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down Expand Up @@ -173,7 +170,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down Expand Up @@ -204,7 +201,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ defaults:

env:
SQLC_VERSION: 1.30.0
WASI_SDK_VERSION: 22
WASI_SDK_VERSION: 25

permissions:
contents: read
Expand Down Expand Up @@ -47,8 +47,8 @@ jobs:

- name: Setup Derived Variables
run: |
echo "WASI_SDK_FOLDER_NAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0" >> $GITHUB_ENV
echo "WASI_SDK_FILENAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-linux.tar.gz" >> $GITHUB_ENV
echo "WASI_SDK_FOLDER_NAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-x86_64-linux" >> $GITHUB_ENV
echo "WASI_SDK_FILENAME=wasi-sdk-${{ env.WASI_SDK_VERSION }}.0-x86_64-linux.tar.gz" >> $GITHUB_ENV

- name: Download Wasi SDK
run: |
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ permissions:
pull-requests: write

env:
DOTNET_VERSION: '8.0.x'

on:
workflow_dispatch:
Expand All @@ -29,7 +28,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Regenerate docs
run: ./docs/scripts/generate_all_docs.sh
Expand Down
9 changes: 7 additions & 2 deletions .github/workflows/legacy-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Set up .NET from global.json
# The .NET Framework projects are built with the Visual Studio MSBuild, which is not guaranteed to support
# the newest .NET SDK that the rest of the repository is pinned to by global.json - so build them with .NET 8
- name: Set up .NET 8
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json
dotnet-version: '8.0.x'

- name: Ignore global.json (pinned to the newer SDK)
run: rm global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ defaults:
shell: bash

env:
DOTNET_VERSION: '8.0.x'
SQLC_VERSION: 1.30.0

permissions:
Expand Down Expand Up @@ -35,6 +34,11 @@ jobs:
steps:
- uses: actions/checkout@v7

- name: Set up .NET from global.json
uses: actions/setup-dotnet@v6
with:
global-json-file: global.json

- uses: sqlc-dev/setup-sqlc@v5
with:
sqlc-version: '${{ env.SQLC_VERSION }}'
Expand All @@ -60,7 +64,7 @@ jobs:
- name: Set up .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
global-json-file: global.json

- name: Load .env file
uses: xom9ikk/dotenv@v2.4.0
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -142,4 +142,6 @@ plugin.wasm
.env.bak
**/.env.bak

**/*.wasm
**/*.wasm
# sqlc plugin cache (Makefile sets SQLCCACHE=./)
/plugins/
35 changes: 22 additions & 13 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@

---

## 🧩 Target Frameworks
- The **plugin** (all projects but `examples`) targets `net10.0`; the SDK is pinned in `global.json`.
- The **generated code** targets the `targetFramework` option: `netstandard2.0`, `netstandard2.1`, `net8.0` (default), `net9.0`, `net10.0`. `DotnetFramework.IsDotnetCore()` is true for every `net*` value; `netstandard*` is "legacy" output.
- The core examples in `sqlc.ci.yaml` are spread over net8.0 / net9.0 / net10.0 so that every framework is built and tested end-to-end.
- The WASM plugin is built as `wasip1` (core module) via overrides in `WasmRunner/WasmRunner.csproj`, because the .NET 10 WASI SDK emits a wasip2 component that sqlc (wazero) cannot load. Re-verify with `sqlc -f sqlc.ci.yaml diff` after SDK upgrades.

---

## 🏗️ Code Generation Flow

```
Expand Down Expand Up @@ -97,8 +105,8 @@ DbDriver InstantiateDriver()

| Option | Default | Description |
|--------|---------|-------------|
| `overrideDriverVersion` | 2.3.6 (MySql), 8.0.3 (Npgsql), 8.0.10 (Sqlite) | Override DB driver version |
| `targetFramework` | net8.0 | .NET Standard 2.0/2.1 or .NET 8.0 |
| `overrideDriverVersion` | 2.4.0 (MySql), 8.0.6 (Npgsql), 10.0.13 (Sqlite) | Override DB driver version |
| `targetFramework` | net8.0 | .NET Standard 2.0/2.1, .NET 8.0, 9.0 or 10.0 (the plugin itself runs on .NET 10, independent of this option) |
| `generateCsproj` | true | Generate .csproj file |
| `namespaceName` | Project name | Override generated namespace |
| `useDapper` | false | Use Dapper wrapper |
Expand Down Expand Up @@ -175,20 +183,21 @@ public partial class Author
### Local Development
```bash
# Prerequisites
dotnet --version # .NET 8.0
dotnet --version # .NET 10 SDK (pinned in global.json)
buf --version
# WASM libs for .NET WASI (see WASM docs)
# WASM build: `dotnet workload install wasi-experimental` + WASI SDK 25 exposed via WASI_SDK_PATH (see docs/08_Contributing.md)

# Generate protobuf
make protobuf-generate
make generate-protobuf

# Generate code
make sqlc-generate-process
make sqlc-generate-wasm
make sqlc-generate # process plugin
make setup-wasm-plugin # WASM plugin -> dist/plugin.wasm

# Test plugins
make test-process-plugin
make test-wasm-plugin
make unit-tests
make test-plugin
sqlc -f sqlc.ci.yaml diff # WASM plugin output must equal the committed examples
```

### Pre-commit Setup
Expand Down Expand Up @@ -249,14 +258,14 @@ for (int i = 0; i < paramArray.Length; i++)

### Generate Code
```bash
make sqlc-generate-process # Process-based plugin
make sqlc-generate-wasm # WASM plugin
make sqlc-generate # Process-based plugin
make setup-wasm-plugin # WASM plugin
```

### Test
```bash
make test-process-plugin
make test-wasm-plugin
make unit-tests
make test-plugin
```

### Release
Expand Down
2 changes: 1 addition & 1 deletion CodeGenerator/CodeGenerator.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp</RootNamespace>
</PropertyGroup>
Expand Down
6 changes: 0 additions & 6 deletions Directory.Build.props

This file was deleted.

2 changes: 1 addition & 1 deletion Drivers/Drivers.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp.Drivers</RootNamespace>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion Drivers/SqliteDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public sealed partial class SqliteDriver(
IList<Query> queries) :
DbDriver(options, catalog, queries), IOne, IMany, IExec, IExecRows, IExecLastId, ICopyFrom
{
private const string DefaultSqliteVersion = "9.0.0";
private const string DefaultSqliteVersion = "10.0.13";

private static readonly HashSet<string> IntegerDbTypes = ["integer", "integernotnulldefaultunixepoch"];

Expand Down
2 changes: 1 addition & 1 deletion Extensions/Extensions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp</RootNamespace>
Expand Down
2 changes: 1 addition & 1 deletion GeneratedProtobuf/GeneratedProtobuf.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp</RootNamespace>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion LocalRunner/LocalRunner.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<PublishSingleFile>true</PublishSingleFile>
<RuntimeIdentifiers>osx-arm64;linux-x64</RuntimeIdentifiers>
<RootNamespace>SqlcGenCsharp</RootNamespace>
Expand Down
15 changes: 11 additions & 4 deletions PluginOptions/DotnetFramework.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;

Expand All @@ -6,6 +7,8 @@ namespace SqlcGenCsharp;
public enum DotnetFramework
{
Dotnet80,
Dotnet90,
Dotnet100,
DotnetStandard20,
DotnetStandard21
}
Expand All @@ -15,6 +18,8 @@ public static class DotnetFrameworkExtensions
private static readonly Dictionary<DotnetFramework, string> EnumToString = new()
{
{ DotnetFramework.Dotnet80, "net8.0" },
{ DotnetFramework.Dotnet90, "net9.0" },
{ DotnetFramework.Dotnet100, "net10.0" },
{ DotnetFramework.DotnetStandard21, "netstandard2.1" },
{ DotnetFramework.DotnetStandard20, "netstandard2.0" }
};
Expand All @@ -26,14 +31,16 @@ public static string ToName(this DotnetFramework me)

public static DotnetFramework ParseName(string dotnetFramework)
{
return EnumToString
.ToDictionary(x => x.Value, x => x.Key)
[dotnetFramework];
var nameToEnum = EnumToString.ToDictionary(x => x.Value, x => x.Key);
if (nameToEnum.TryGetValue(dotnetFramework, out var parsed))
return parsed;
throw new ArgumentException(
$"Unsupported targetFramework '{dotnetFramework}', supported values: {string.Join(", ", nameToEnum.Keys)}");
}

public static bool IsDotnetCore(this DotnetFramework me)
{
return me == DotnetFramework.Dotnet80;
return me is DotnetFramework.Dotnet80 or DotnetFramework.Dotnet90 or DotnetFramework.Dotnet100;
}

public static bool IsDotnetLegacy(this DotnetFramework me)
Expand Down
2 changes: 1 addition & 1 deletion PluginOptions/PluginOptions.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp</RootNamespace>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion SqlcGenCsharp/SqlcGenCsharp.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net10.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<RootNamespace>SqlcGenCsharp</RootNamespace>
Expand Down
Loading
Loading