PL/Swift allows you to write custom SQL functions and types for the PostgreSQL database server in the Swift programming language.
A small tutorial can be found over here: PL/Swift - PostgreSQL Functions in Swift.
Despite the name it is not (currently) a language extension like say PL/Python, which allows you to directly embed Swift code in SQL. Instead it provides the infrastructure to create PostgreSQL dynamically loadable objects.
This project/sourcedir contains the swift-pl
tool,
Xcode base configurations and module maps for the PostgreSQL server.
A dynamically loadable PostgreSQL extension module consists of those files:
CREATE FUNCTION
)NOTE: This requires a PL/Swift installation. W/o it, it will fail to built CPLSwift!
If you setup a new module from scratch, use:
swift pl init
for example:
mkdir base36 && cd base36
swift pl init
Otherwise setup your Package.swift to include PLSwift:
import PackageDescription
let package = Package(
name: "MyTool",
dependencies: [
.Package(url: "[email protected]:PL-Swift/PLSwift.git", from: "0.5.0"),
]
)
Note: If you are using Swift older than 4.2, you need to use the swift3
branch (0.3.0
version tag).
Simply invoke
swift pl build
This wraps Swift Package Manager to build your package and then produces a proper module which can be loaded into PostgreSQL.
To install the module into the local PostgreSQL, call:
swift pl install
That is very simple, just do a:
CREATE EXTENSION helloswift;
If you rebuild the extension and need to reload, you probably need to
restart / reconnected
psql
and do a DROP EXTENSION xyz
first.
Consider this a demo. Though it should work just fine.
Plans:
PL/Swift is brought to you by ZeeZide. We like feedback, GitHub stars, cool contract work, presumably any form of praise you can think of.
ApacheExpress |
mod_swift |
ZeeQL |
link |
Stars: 43 |
Last commit: 4 years ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics