Questions tagged [server-side-swift]
79 questions
3
votes
1 answer
Find all items with empty many to many relationship in vapor fluent
Given the example from the vapor docs:
// Example of a pivot model.
final class PlanetTag: Model {
static let schema = "planet+tag"
@ID(key: .id)
var id: UUID?
@Parent(key: "planet_id")
var planet: Planet
@Parent(key:…

dehlen
- 7,325
- 4
- 43
- 71
3
votes
1 answer
Unable to persist data across instances of web service in Swift using Vapor-Fluent
I'm writing a web service in Swift using Vapor framework.
I use FluentSQLite to save data. I have a User Model which conforms to the SQLiteModel and Migration. I have added routes to create new user via a post methods and return the list of users…

imthath
- 1,353
- 1
- 13
- 35
3
votes
2 answers
Swift Linux Generate Random Bool
I am trying to make a static extension of Bool to return a random true/false value whenever called. I am trying to make this work:
static func coinFlip() -> Bool {
#if os(Linux)
srand(UInt32(time(nil)))
let result = Int(random() % 2)
…

dokun1
- 2,120
- 19
- 37
3
votes
1 answer
Which server side swift framework is best?
I'm looking forward to learn swift in server side. I'm not sure which server side framework is good. There is perfect, vapor, kitura, zevo and some more frameworks. Which one of them is good.

Mahil Arasu
- 105
- 1
- 8
3
votes
2 answers
How do I download a file and send a file using Vapor server side swift?
How do I download a file using server side swift?
I have tried this:
let result = try drop.client.get("http://dropcanvas.com/ir4ok/1")
but result.body always = 0 elements
How do I send a file?
I have tried this
drop.get("theFile") { request in…

Just a coder
- 15,480
- 16
- 85
- 138
2
votes
1 answer
How to update field from required to optional using vapor (fluent migration)?
I'm use vapor 4
struct MakeRegionOptional: AsyncMigration {
func prepare(on database: Database) async throws {
try await database.schema("Attraction")
.updateField("region", .string)
.update()
}
…

Mitul Pokiya
- 93
- 9
2
votes
1 answer
How do you extend templates in Leaf using the #extend and #export tags in leaf?
The Leaf documentation doesn't seem to be working for me I can't figure out why.
child.leaf
#extend("index"):
#export("hello"):
Welcome to Vapor!
#endexport #endextend index.leaf
Ethan Mofokeng
- 21
- 3
2
votes
2 answers
Vapor uploads files to DerivedData instead of the Public folder in the project structure
When I try to upload files via my Vapor server, it always uploads files into the DerivedData folder instead of the Public folder inside the project structure.
I can verify that the file is created in the path, but the path is somewhere in…

kalafun
- 3,512
- 6
- 35
- 49
2
votes
1 answer
Deploying init vapor 4 project causing error
I've tried deploying an init vapor 4 project on Heroku and Digital Ocean and keep getting the same error:
error: https://github.com/vapor/vapor.git has no Package.swift manifest for version 4.4.1
my swift package is pointing to:
.package(url:…

Yuliani Noriega
- 1,085
- 12
- 23
2
votes
1 answer
Manually modifying model property values in vapor 4 response
I have a vapor 4 application. I do a query from database for getting some items and I want to perform some manual calculation based on the returned values before finishing the request. here a sample code of what I am trying to achieve.
final class…
user7649191
2
votes
1 answer
Linking my Fluent model to a pre-existing database table
I've been trying to link up my PostgreSQL database to a Swift Vapor project so I create routes to it. The first table I want to access is a table in my_database calls users. It has the properties user_id (primary integer key) and created_on…

ADB
- 591
- 7
- 21
2
votes
1 answer
Wait for async task to complete in request in Vapor
I am writing an API using the server side swift framework Vapor. My model is very simple. I have a Workout table, which has a to many relationship to the Circuit table, which has a to many relationship with the Exercise table. When the api consumer…

Chandler De Angelis
- 2,646
- 6
- 32
- 45
2
votes
1 answer
database does not exist - PostgreSQL in Server Side Swift using Vapor 3 and Fluent
I'm writing a web service in Swift using Vapor 3. I'm using FluentPostgreSQL for data persistence. I have a user model which conforms to both PostgreSQLModel, PostgreSQLMigration. The app builds correctly. However, when I run the app, I am getting…

imthath
- 1,353
- 1
- 13
- 35
2
votes
1 answer
Why Xcode keeps substituting generics with '_'
I am making a server with Swift 5 and Vapor 3. When setting up a route I want to call a function from my controller that returns an optional like so:
//Person.swift
struct Person: Content {
...
}
//PersonController.swift
func update(_…

lsauceda
- 315
- 3
- 12
2
votes
1 answer
Server Side Swift Vapor - Model inheritance
Is it possible to subclass models and inherit the superclass's properties
so in the end I have the models:
class User
- class Student : User
- class Teacher : User
With the intention of creating this:…

ElectricPenguin
- 83
- 6