Skip to content

Commit abba19d

Browse files
committed
updated README.md
1 parent 1619994 commit abba19d

1 file changed

Lines changed: 56 additions & 24 deletions

File tree

README.md

Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,45 @@
11
# SQLClient-Swift
22

3-
A Swift wrapper around FreeTDS (db-lib) for connecting to Microsoft SQL Server from macOS, iOS, and Linux.
3+
A modern, high-performance Swift client for **Microsoft SQL Server**, built for macOS, iOS, and Linux.
4+
5+
This library is a lightweight Swift wrapper around the **FreeTDS (db-lib)** C library. It provides a clean, native Swift interface with full support for modern Swift features like `Async/Await`.
46

57
## Features
68

7-
- **Async/Await Support**: Modern Swift concurrency support.
8-
- **FreeTDS 1.x Compatible**: Supports modern SQL Server features like `DATETIME2`, `NVARCHAR(MAX)`, and encryption.
9-
- **Robust Connection Handling**: Optimized for both Homebrew (macOS) and APT (Linux) builds of FreeTDS.
10-
- **Backward Compatible**: Works with older FreeTDS versions by gracefully falling back on advanced features.
9+
- **Modern Concurrency**: Full `Async/Await` support for non-blocking database operations.
10+
- **Cross-Platform**: Works seamlessly on macOS (via Homebrew) and Linux (via APT).
11+
- **FreeTDS 1.x Optimized**:
12+
- Supports modern SQL Server types: `DATETIME2`, `NVARCHAR(MAX)`, `UNIQUEIDENTIFIER` (UUID), etc.
13+
- Handles affected-row counts (`dbcount`) for DML operations.
14+
- Support for named encryption modes (`off`, `request`, `require`, `strict` for TDS 8.0).
15+
- **Robust & Compatible**:
16+
- Automatically detects and handles different FreeTDS build modes (Sybase vs. Microsoft).
17+
- Gracefully falls back on advanced features for older FreeTDS versions.
18+
- Fixes the legacy "MONEY truncation" bug in older libraries.
19+
- **Thread-Safe**: Uses internal serial dispatch queues to safely manage the underlying C state.
20+
21+
## Installation
1122

12-
## Requirements
23+
### 1. Install FreeTDS
1324

14-
### macOS
15-
- Install FreeTDS via Homebrew: `brew install freetds`
25+
#### macOS (Homebrew)
26+
```bash
27+
brew install freetds
28+
```
1629

17-
### Linux (Ubuntu/Debian)
18-
- Install FreeTDS development files: `sudo apt-get install freetds-dev freetds-bin`
30+
#### Linux (Ubuntu/Debian)
31+
```bash
32+
sudo apt-get update
33+
sudo apt-get install freetds-dev freetds-bin
34+
```
1935

20-
## Installation
36+
### 2. Add to Swift Package Manager
2137

22-
Add this package to your `Package.swift`:
38+
Add the dependency to your `Package.swift`:
2339

2440
```swift
2541
dependencies: [
26-
.package(url: "https://github.com/YOUR_USERNAME/SQLClient-Swift.git", from: "1.0.0")
42+
.package(url: "https://github.com/vkuttyp/SQLClient-Swift.git", from: "1.0.0")
2743
]
2844
```
2945

@@ -42,44 +58,60 @@ targets: [
4258

4359
## Usage
4460

45-
### Simple Connection
61+
### Simple Connection (Async/Await)
4662

4763
```swift
4864
import SQLClient
4965

5066
let client = SQLClient.shared
67+
68+
// Note: For some Linux/Sybase-mode builds, include the port in the host string
5169
let connected = await client.connect(
52-
server: "your-server.com:1433",
70+
server: "sql.marivil.com:1433",
5371
username: "sa",
5472
password: "your-password",
55-
database: "MyDatabase"
73+
database: "TestDB"
5674
)
5775

5876
if connected {
59-
let results = await client.execute("SELECT * FROM Users")
60-
print(results)
77+
let results = await client.execute("SELECT * FROM Products")
78+
for table in results {
79+
for row in table {
80+
print(row["title"] ?? "No Title")
81+
}
82+
}
6183
}
6284
```
6385

64-
### Advanced Connection Options
86+
### Advanced Configuration
87+
88+
Use `SQLClientConnectionOptions` to tune timeouts, encryption, and more:
6589

6690
```swift
6791
var options = SQLClientConnectionOptions(
68-
server: "your-server.com",
92+
server: "vps.marivil.com",
6993
username: "sa",
70-
password: "your-password",
71-
database: "MyDatabase"
94+
password: "password"
7295
)
73-
options.port = 1433
96+
options.port = 1430
97+
options.database = "SwiftTestDb"
7498
options.encryption = .require
7599
options.loginTimeout = 10
100+
options.queryTimeout = 30
76101

77102
let connected = await client.connect(options: options)
78103
```
79104

105+
### Handling Affected Rows
106+
107+
```swift
108+
let result = await client.executeWithResult("UPDATE Products SET price = 19.99 WHERE id = 1")
109+
print("Rows changed: \(result.rowsAffected)")
110+
```
111+
80112
## Environment Variables
81113

82-
You can set the `TDSVER` environment variable to control the protocol version (defaults to `7.4`).
114+
The library defaults to **TDS version 7.4** (compatible with SQL Server 2012-2022). You can override this via the `TDSVER` environment variable:
83115

84116
```bash
85117
export TDSVER=7.4

0 commit comments

Comments
 (0)