Skip to content

Commit 745f8ff

Browse files
vkuttypCopilot
andcommitted
Initial commit: sql-nio unified Swift NIO SQL driver
- MSSQL (TDS 7.4), PostgreSQL, MySQL, SQLite drivers - Unified async/await API with SQLDatabase protocol - SQLValue, SQLRow, SQLDataTable, SQLDataSet - Connection pooling, transactions, Codable decoding - Backup/restore utilities for all 4 databases - Windows/NTLM authentication for MSSQL - @p1 and ? placeholder syntax - DocC documentation for all 5 modules - GitHub Actions CI/docs/release workflows - MIT License Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 parents  commit 745f8ff

86 files changed

Lines changed: 18475 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/ci.yml

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [main, develop]
6+
paths-ignore:
7+
- '**.md'
8+
- '.spi.yml'
9+
- 'Sources/**/*.docc/**'
10+
pull_request:
11+
branches: [main]
12+
paths-ignore:
13+
- '**.md'
14+
- '.spi.yml'
15+
- 'Sources/**/*.docc/**'
16+
17+
concurrency:
18+
group: ${{ github.workflow }}-${{ github.ref }}
19+
cancel-in-progress: true
20+
21+
# ─────────────────────────────────────────────────────────────────────────────
22+
# Environment variables shared across all jobs
23+
# ─────────────────────────────────────────────────────────────────────────────
24+
env:
25+
SWIFT_VERSION: "6.0"
26+
27+
jobs:
28+
# ───────────────────────────────────────────────────────────────────────────
29+
# 1. Build + SQLite tests — macOS and Linux, multiple Swift versions
30+
# No Docker needed — SQLite uses an in-memory database.
31+
# ───────────────────────────────────────────────────────────────────────────
32+
test-sqlite:
33+
name: SQLite — ${{ matrix.os }} / Swift ${{ matrix.swift }}
34+
runs-on: ${{ matrix.os }}
35+
strategy:
36+
fail-fast: false
37+
matrix:
38+
os: [macos-15, ubuntu-24.04]
39+
swift: ["5.10", "6.0"]
40+
exclude:
41+
# macOS 15 ships with Swift 6 (Xcode 16); skip redundant 5.10 run
42+
- os: macos-15
43+
swift: "5.10"
44+
steps:
45+
- name: Checkout
46+
uses: actions/checkout@v4
47+
48+
- name: Setup Swift ${{ matrix.swift }}
49+
if: runner.os == 'Linux'
50+
uses: swift-actions/setup-swift@v2
51+
with:
52+
swift-version: ${{ matrix.swift }}
53+
54+
- name: Cache SPM
55+
uses: actions/cache@v4
56+
with:
57+
path: .build
58+
key: ${{ runner.os }}-spm-${{ matrix.swift }}-${{ hashFiles('Package.resolved') }}
59+
restore-keys: |
60+
${{ runner.os }}-spm-${{ matrix.swift }}-
61+
62+
- name: Build
63+
run: swift build --configuration debug 2>&1
64+
65+
- name: Run SQLite tests
66+
run: swift test --filter SQLiteNioTests 2>&1
67+
68+
- name: Run Core tests
69+
run: swift test --filter SQLNioCoreTests 2>&1
70+
71+
# ───────────────────────────────────────────────────────────────────────────
72+
# 2. SQL Server integration tests
73+
# Uses GitHub Actions service container — Linux only.
74+
# ───────────────────────────────────────────────────────────────────────────
75+
test-mssql:
76+
name: SQL Server integration tests
77+
runs-on: ubuntu-24.04
78+
services:
79+
mssql:
80+
image: mcr.microsoft.com/mssql/server:2022-latest
81+
env:
82+
ACCEPT_EULA: "Y"
83+
SA_PASSWORD: "aBCD111!"
84+
MSSQL_PID: Developer
85+
ports:
86+
- 1433:1433
87+
options: >-
88+
--health-cmd "/opt/mssql-tools18/bin/sqlcmd -S localhost -U sa -P 'aBCD111!' -Q 'SELECT 1' -C"
89+
--health-interval 10s
90+
--health-timeout 5s
91+
--health-retries 15
92+
steps:
93+
- name: Checkout
94+
uses: actions/checkout@v4
95+
96+
- name: Setup Swift
97+
uses: swift-actions/setup-swift@v2
98+
with:
99+
swift-version: ${{ env.SWIFT_VERSION }}
100+
101+
- name: Cache SPM
102+
uses: actions/cache@v4
103+
with:
104+
path: .build
105+
key: ${{ runner.os }}-spm-mssql-${{ hashFiles('Package.resolved') }}
106+
restore-keys: |
107+
${{ runner.os }}-spm-mssql-
108+
109+
- name: Create test database
110+
run: |
111+
until /opt/mssql-tools18/bin/sqlcmd -S 127.0.0.1 -U sa -P 'aBCD111!' -C \
112+
-Q "CREATE DATABASE MSSQLNioTestDb" 2>/dev/null; do
113+
echo "Waiting for SQL Server..."; sleep 3
114+
done
115+
116+
- name: Run MSSQL tests
117+
env:
118+
MSSQL_TEST_HOST: "127.0.0.1"
119+
MSSQL_TEST_PASS: "aBCD111!"
120+
MSSQL_TEST_DB: "MSSQLNioTestDb"
121+
MSSQL_TEST_USER: "sa"
122+
run: swift test --filter MSSQLNioTests 2>&1
123+
124+
# ───────────────────────────────────────────────────────────────────────────
125+
# 3. PostgreSQL integration tests
126+
# ───────────────────────────────────────────────────────────────────────────
127+
test-postgres:
128+
name: PostgreSQL integration tests
129+
runs-on: ubuntu-24.04
130+
services:
131+
postgres:
132+
image: postgres:16-alpine
133+
env:
134+
POSTGRES_DB: PostgresNioTestDb
135+
POSTGRES_USER: pguser
136+
POSTGRES_PASSWORD: pgPass123
137+
ports:
138+
- 5432:5432
139+
options: >-
140+
--health-cmd "pg_isready -U pguser -d PostgresNioTestDb"
141+
--health-interval 5s
142+
--health-timeout 3s
143+
--health-retries 10
144+
steps:
145+
- name: Checkout
146+
uses: actions/checkout@v4
147+
148+
- name: Setup Swift
149+
uses: swift-actions/setup-swift@v2
150+
with:
151+
swift-version: ${{ env.SWIFT_VERSION }}
152+
153+
- name: Cache SPM
154+
uses: actions/cache@v4
155+
with:
156+
path: .build
157+
key: ${{ runner.os }}-spm-pg-${{ hashFiles('Package.resolved') }}
158+
restore-keys: |
159+
${{ runner.os }}-spm-pg-
160+
161+
- name: Run PostgreSQL tests
162+
env:
163+
PG_TEST_HOST: "127.0.0.1"
164+
PG_TEST_DB: PostgresNioTestDb
165+
PG_TEST_USER: pguser
166+
PG_TEST_PASS: pgPass123
167+
run: swift test --filter PostgresNioTests 2>&1
168+
169+
# ───────────────────────────────────────────────────────────────────────────
170+
# 4. MySQL integration tests
171+
# ───────────────────────────────────────────────────────────────────────────
172+
test-mysql:
173+
name: MySQL integration tests
174+
runs-on: ubuntu-24.04
175+
services:
176+
mysql:
177+
image: mysql:8
178+
env:
179+
MYSQL_DATABASE: MySQLNioTestDb
180+
MYSQL_USER: mysqluser
181+
MYSQL_PASSWORD: mysqlPass123
182+
MYSQL_ROOT_PASSWORD: root
183+
ports:
184+
- 3306:3306
185+
options: >-
186+
--health-cmd "mysqladmin ping -u mysqluser -pmysqlPass123"
187+
--health-interval 5s
188+
--health-timeout 3s
189+
--health-retries 15
190+
steps:
191+
- name: Checkout
192+
uses: actions/checkout@v4
193+
194+
- name: Setup Swift
195+
uses: swift-actions/setup-swift@v2
196+
with:
197+
swift-version: ${{ env.SWIFT_VERSION }}
198+
199+
- name: Cache SPM
200+
uses: actions/cache@v4
201+
with:
202+
path: .build
203+
key: ${{ runner.os }}-spm-mysql-${{ hashFiles('Package.resolved') }}
204+
restore-keys: |
205+
${{ runner.os }}-spm-mysql-
206+
207+
- name: Run MySQL tests
208+
env:
209+
MYSQL_TEST_HOST: "127.0.0.1"
210+
MYSQL_TEST_DB: MySQLNioTestDb
211+
MYSQL_TEST_USER: mysqluser
212+
MYSQL_TEST_PASS: mysqlPass123
213+
run: swift test --filter MySQLNioTests 2>&1
214+
215+
# ───────────────────────────────────────────────────────────────────────────
216+
# 5. Summary / Required status check
217+
# PRs cannot be merged until all four test jobs pass.
218+
# ───────────────────────────────────────────────────────────────────────────
219+
ci-success:
220+
name: All tests passed
221+
runs-on: ubuntu-24.04
222+
needs: [test-sqlite, test-mssql, test-postgres, test-mysql]
223+
if: always()
224+
steps:
225+
- name: Check results
226+
run: |
227+
if [[ "${{ needs.test-sqlite.result }}" != "success" || \
228+
"${{ needs.test-mssql.result }}" != "success" || \
229+
"${{ needs.test-postgres.result }}" != "success" || \
230+
"${{ needs.test-mysql.result }}" != "success" ]]; then
231+
echo "One or more test jobs failed."
232+
exit 1
233+
fi
234+
echo "All test jobs passed."

.github/workflows/docs.yml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Documentation
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'Sources/**'
8+
- 'Package.swift'
9+
- 'Package.resolved'
10+
workflow_dispatch: # allow manual trigger
11+
12+
permissions:
13+
contents: read
14+
pages: write
15+
id-token: write
16+
17+
concurrency:
18+
group: pages
19+
cancel-in-progress: true
20+
21+
jobs:
22+
build-docs:
23+
name: Build DocC
24+
runs-on: macos-15 # Xcode 16 / Swift 6
25+
steps:
26+
- name: Checkout
27+
uses: actions/checkout@v4
28+
29+
- name: Cache SPM
30+
uses: actions/cache@v4
31+
with:
32+
path: .build
33+
key: macos-spm-docs-${{ hashFiles('Package.resolved') }}
34+
restore-keys: |
35+
macos-spm-docs-
36+
37+
- name: Setup GitHub Pages
38+
uses: actions/configure-pages@v5
39+
40+
- name: Build documentation for all modules
41+
run: |
42+
mkdir -p docs
43+
for TARGET in SQLNioCore MSSQLNio PostgresNio MySQLNio SQLiteNio; do
44+
echo "▶ Building docs for $TARGET"
45+
swift package \
46+
--allow-writing-to-directory "docs/$TARGET" \
47+
generate-documentation \
48+
--target "$TARGET" \
49+
--disable-indexing \
50+
--transform-for-static-hosting \
51+
--hosting-base-path "sql-nio/$TARGET" \
52+
--output-path "docs/$TARGET"
53+
done
54+
55+
# Create a landing index.html that links to each module's docs
56+
- name: Generate landing page
57+
run: |
58+
cat > docs/index.html << 'HTML'
59+
<!DOCTYPE html>
60+
<html lang="en">
61+
<head>
62+
<meta charset="UTF-8">
63+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
64+
<title>sql-nio Documentation</title>
65+
<style>
66+
body { font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
67+
max-width: 720px; margin: 60px auto; padding: 0 24px; color: #1d1d1f; }
68+
h1 { font-size: 2rem; margin-bottom: 0.25em; }
69+
p { color: #6e6e73; }
70+
ul { list-style: none; padding: 0; display: grid; gap: 12px; margin-top: 32px; }
71+
li a { display: block; padding: 20px 24px; border: 1px solid #d2d2d7;
72+
border-radius: 12px; text-decoration: none; color: inherit;
73+
transition: box-shadow .15s; }
74+
li a:hover { box-shadow: 0 4px 16px rgba(0,0,0,.1); }
75+
li a strong { display: block; font-size: 1.1rem; color: #0071e3; }
76+
li a span { font-size: .9rem; color: #6e6e73; margin-top: 4px; display: block; }
77+
</style>
78+
</head>
79+
<body>
80+
<h1>sql-nio</h1>
81+
<p>A unified Swift NIO-based SQL driver for SQL Server, PostgreSQL, MySQL, and SQLite.</p>
82+
<ul>
83+
<li><a href="SQLNioCore/documentation/sqlniocore/">
84+
<strong>SQLNioCore</strong>
85+
<span>Shared protocol, types &amp; utilities — SQLDatabase, SQLValue, SQLRow, SQLDataTable</span>
86+
</a></li>
87+
<li><a href="MSSQLNio/documentation/mssqlnio/">
88+
<strong>MSSQLNio</strong>
89+
<span>Microsoft SQL Server driver — TDS 7.4 wire protocol, NTLM auth, stored procedures</span>
90+
</a></li>
91+
<li><a href="PostgresNio/documentation/postgresnio/">
92+
<strong>PostgresNio</strong>
93+
<span>PostgreSQL driver — wire protocol v3, SCRAM-SHA-256 auth</span>
94+
</a></li>
95+
<li><a href="MySQLNio/documentation/mysqlnio/">
96+
<strong>MySQLNio</strong>
97+
<span>MySQL / MariaDB driver — wire protocol v10, caching_sha2_password auth</span>
98+
</a></li>
99+
<li><a href="SQLiteNio/documentation/sqlitenio/">
100+
<strong>SQLiteNio</strong>
101+
<span>Embedded SQLite — in-memory &amp; file databases, native binary backup</span>
102+
</a></li>
103+
</ul>
104+
</body>
105+
</html>
106+
HTML
107+
108+
- name: Upload Pages artifact
109+
uses: actions/upload-pages-artifact@v3
110+
with:
111+
path: docs
112+
113+
deploy-docs:
114+
name: Deploy to GitHub Pages
115+
needs: build-docs
116+
runs-on: ubuntu-24.04
117+
environment:
118+
name: github-pages
119+
url: ${{ steps.deployment.outputs.page_url }}
120+
steps:
121+
- name: Deploy
122+
id: deployment
123+
uses: actions/deploy-pages@v4

0 commit comments

Comments
 (0)