vapor

Is is possible to use Vapor 3 Postgres Fluent in a standalone script?

微笑、不失礼 提交于 2020-05-27 04:51:22
问题 I am experimenting with a standalone script that will query a Postgres database using Vapor and Fluent. In a normal Vapor API application this is simply done by: router.get("products") { request in return Product.query(on: request).all() } However, in a standalone script, since there is no "request", I get stuck on what to replace the "request" or DatabaseConnectable with. Here's where I get stuck on: import Fluent import FluentPostgreSQL let databaseConfig = PostgreSQLDatabaseConfig(hostname

Compiling Vapor as Standalone App on MacOS

眉间皱痕 提交于 2020-05-25 20:32:17
问题 I would like to compile Vapor with my code as a MacOS app so I can place it on internal server (drag and click to launch it). I would prefer not to have to install Xcode, swift and other development files on the server. I am new to vapor and swift. I have things running when I build it from xCode. Someone else asked if they could embed it in app, there was yes and no response. The yes did not provide any direction as to how to do it. Can it be compiled to a standalone OSX App? What do I need

Siblings relationship between same models in Vapor

人盡茶涼 提交于 2020-04-13 17:15:40
问题 I have a User model which I want to add a friends property to. Friends, are supposed to be other User s. I created the UserFriendsPivot : final class UserFriendsPivot: MySQLPivot, ModifiablePivot { var id: Int? var userID: User.ID var friendID: User.ID typealias Left = User typealias Right = User static var leftIDKey: WritableKeyPath<UserFriendsPivot, Int> { return \.userID } static var rightIDKey: WritableKeyPath<UserFriendsPivot, Int> { return \.friendID } init(_ user: User, _ friend: User)

Swift: What does backslash dot “\.” mean?

痞子三分冷 提交于 2020-04-05 15:49:27
问题 I'm new to backend Swift and thought I'd use Vapor to get up-and-running on a side project fast... I ran vapor new WebServer --template=auth-template , and now I'm trying to figure out what something like return \.email means. For more context, I'm looking in WebServer > Sources > App > Models > Users.swift: import Authentication import FluentSQLite import Vapor /// Allows users to be verified by basic / password auth middleware. extension User: PasswordAuthenticatable { /// See

How do I download a file and send a file using Vapor server side swift?

烂漫一生 提交于 2020-02-28 08:08:27
问题 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 let file = NSData(contentsOf: "/Users/bob.zip") return file // This fails here } 回答1: Download a file. You are on the right track here, but the reason why result.body is always empty is because your file service is returning a 302 redirection rather

Vapor 3 Rendering leaf template with script inline

最后都变了- 提交于 2020-02-04 22:58:36
问题 I am trying to render a template in Vapor 3 with Leaf. Most of my HTML is in my base.leaf. In the login.leaf template, I need to add a JS script. Trouble is when it gets to the function it breaks and renders the function. Can anyone tell me how to add these properly? Thanks for your help in advance. Here's what is giving me problems: #set("content") { <h1>#(title)</h1> <div id="logo"><img src="images/global/journey_trax_logo.png" alt=""/></div> <div id="sheet1" class="form_sheet"> <input type

Vapor 3 Rendering leaf template with script inline

有些话、适合烂在心里 提交于 2020-02-04 22:57:53
问题 I am trying to render a template in Vapor 3 with Leaf. Most of my HTML is in my base.leaf. In the login.leaf template, I need to add a JS script. Trouble is when it gets to the function it breaks and renders the function. Can anyone tell me how to add these properly? Thanks for your help in advance. Here's what is giving me problems: #set("content") { <h1>#(title)</h1> <div id="logo"><img src="images/global/journey_trax_logo.png" alt=""/></div> <div id="sheet1" class="form_sheet"> <input type

Not able to add Items to Database

南笙酒味 提交于 2020-01-24 19:33:09
问题 // This is a continuation of the questions I have asked from a tutorial by Paul Hudson on youtube - I have tried to add items to a database (see image below) - When I should click on the "Add" button on the image above, the boxes should become EMPTY (See image below). Though .Quantum Pizza will not be added to the list of .Statin Island Pizza and .Country pizza, because I have not done further coding), but it should be as the image below - but, the result is as follows - Now, I am posting the

Is it possible to access fields in a joined table in Vapor?

烈酒焚心 提交于 2020-01-14 14:36:27
问题 I have a Persons table and an Events table that are related via an Attends table, such that a record exists the Attends table when I wish to record the fact that a person is due to attend a particular Event in a particular role (e.g. organiser, etc.): Persons +----+-------------+ | id | surname | +----+-------------+ | 1 | Robinson | | 2 | Savage | ... Events +----+-----------------------+ | id | name | +----+-----------------------+ | 1 | Half Term Competition | | 2 | Christmas Competition |

Vapor Installation Issues (First time using Vapor) using Swift 5

非 Y 不嫁゛ 提交于 2020-01-13 15:46:07
问题 After installing vapor i am getting below error dyld: Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib Referenced from: /usr/local/bin/vapor Reason: image not found Abort trap: 6 Here lies my issue, I have no idea how to solve that.even I am not able to create new project. Please help. 回答1: I never faced with that issue but saw this tricky solution in some chat ln -s /usr/local/opt/openssl/lib/libssl.1.1.dylib /usr/local/opt/openssl/lib/libssl.1.0.0.dylib ln -s /usr/local/opt