Add SQLite system library package

This commit is contained in:
2025-04-23 20:28:12 +03:00
parent 77639572ea
commit 53e654532d
6 changed files with 153 additions and 0 deletions

17
.gitignore vendored Normal file
View File

@@ -0,0 +1,17 @@
## General
.DS_Store
.swiftpm
.build/
## Various settings
Package.resolved
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata/
*.xcuserdatad/

15
.swift-format Normal file
View File

@@ -0,0 +1,15 @@
{
"fileScopedDeclarationPrivacy": {
"accessLevel": "private"
},
"indentBlankLines": true,
"indentation": {
"spaces": 4
},
"lineLength": 9999,
"maximumBlankLines": 1,
"multiElementCollectionTrailingCommas": false,
"rules": {
"FileScopedDeclarationPrivacy": true
}
}

27
Package.swift Normal file
View File

@@ -0,0 +1,27 @@
// swift-tools-version: 5.10
// The swift-tools-version declares the minimum version of Swift required to build this package.
import PackageDescription
#if os(Linux)
let sqlitePkg = "sqlite3"
#else
let sqlitePkg: String? = nil
#endif
let package = Package(
name: "DataLiteC",
platforms: [
.macOS(.v10_14),
.iOS(.v12)
],
products: [
.library(name: "DataLiteC", targets: ["DataLiteC"])
],
targets: [
.systemLibrary(name: "DataLiteC", pkgConfig: sqlitePkg, providers: [
.apt(["sqlite3", "libsqlite3-dev"]),
.brew(["sqlite"])
])
]
)

View File

@@ -1 +1,84 @@
# DataLiteC Package # DataLiteC Package
**DataLiteC** is a Swift package that provides a system interface to the SQLite C library. It supports **macOS**, **iOS**, and **Linux** platforms, using the system SQLite library via `pkg-config`.
## Overview
DataLiteC is a Swift system library wrapper that links directly to the SQLite C API. It does not add any abstractions and enables direct usage of SQLite's C functions within Swift code.
## Installation
### Adding DataLiteC to Your Project
To use DataLiteC in your Swift project, add it to the dependencies section of your `Package.swift` file:
```swift
// swift-tools-version: 5.10
import PackageDescription
let package = Package(
name: "YourProject",
dependencies: [
.package(url: "https://github.com/angd-dev/data-lite-c.git", from: "1.0.0")
],
targets: [
.target(
name: "YourTarget",
dependencies: [
.product(name: "DataLiteC", package: "data-lite-c")
]
)
]
)
```
### System Requirements
DataLiteC requires SQLite to be installed on your system:
- **Linux**: Install `sqlite3` and development headers:
```bash
sudo apt-get install sqlite3 libsqlite3-dev
```
- **macOS**: Install SQLite using Homebrew:
```bash
brew install sqlite
```
## Usage
Once the package is added, you can import it and use SQLite's C API directly:
```swift
import DataLiteC
var db: OpaquePointer?
if sqlite3_open(":memory:", &db) == SQLITE_OK {
print("Successfully opened connection to database.")
sqlite3_close(db)
} else {
print("Unable to open database.")
}
```
## Troubleshooting
If you encounter build errors such as missing `sqlite3.h`, ensure that `pkg-config` can locate SQLite:
```bash
pkg-config --cflags sqlite3
```
If the command returns nothing, manually set the `PKG_CONFIG_PATH`:
```bash
export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"
```
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.

View File

@@ -0,0 +1,5 @@
module DataLiteC [system] {
header "shim.h"
link "sqlite3"
export *
}

6
Sources/DataLiteC/shim.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef C_SQLITE_H
#define C_SQLITE_H
#include <sqlite3.h>
#endif