vapor-community / fluent-provider Goto Github PK
View Code? Open in Web Editor NEWA provider for including Fluent in Vapor applications
License: MIT License
A provider for including Fluent in Vapor applications
License: MIT License
Using a raw Query with Fluent I get wrong numbers from my query
guard let majorSet = try? Job.database?.raw("select major, avg(pay) as average from jobs group by major order by average desc").converted(to: JSON.self).makeResponse() else { throw SQL.serialization }
I get the following Response which is wrong:
[
{
"major": "Product Design",
"average": "0.000000116400"
},
{
"major": "Software Engineering",
"average": "0.000000000009"
},
{
"major": "Computer Science",
"average": "0.000000082500"
},
{
"major": "Computer Engineering",
"average": "0.000000065000"
},
{
"major": "Chemical Engineering",
"average": "0.000000058224"
},
{
"major": "Accounting",
"average": "0.000000055000"
},
{
"major": "Information Technology",
"average": "0.000000054000"
},
{
"major": "Marketing",
"average": "0.000000036000"
}
]
As those values should be whole numbers
Unlike other parts of Vapor, the SQLite configuration does not prepend the calculated working directory to the database path.
When the project is executed in Xcode with default scheme settings, this results in the database file being created in DerivedData instead of the project folder.
(Command line and Linux builds are not affected.)
If we log using the following
drop.database?.log = { query in
print(query)
}
The the queries for the preparations are not logged as they are called during the init of the Droplet.
Vapor Toolbox: 2.0.3
Vapor Framework: 2.1.2
Given the following code, Updateable
protocol can not convert null
to nil
for the string as expected:
final class Reminder: Model {
var calendarItemIdentifier: String?
struct Properties {
static let idKey = "id"
static let calendarItemIdentifierKey = "calendar_item_identifier"
}
init(row: Row) throws {
calendarItemIdentifier = try? row.get(Properties.calendarItemIdentifierKey)
}
func makeRow() throws -> Row {
var row = Row()
try row.set(Properties.calendarItemIdentifierKey, calendarItemIdentifier)
}
extension Reminder: Preparation {
static func prepare(_ database: Database) throws {
try database.create(self) { reminder in
reminder.id()
reminder.string(Properties.calendarItemIdentifierKey, optional: true)
}
}
static func revert(_ database: Database) throws {
try database.delete(self)
}
}
extension Reminder: Updateable {
public static var updateableKeys: [UpdateableKey<Reminder>] {
return [
UpdateableKey(Properties.calendarItemIdentifierKey, String.self) { object, calendarItemIdentifier in
object.calendarItemIdentifier = calendarItemIdentifier
}
]
}
}
Attempting to patch through
func update(req: Request, reminder: Reminder) throws -> ResponseRepresentable {
try reminder.update(for: req)
try reminder.save()
return try reminder
}
With
{
"calendar_item_identifier": null
}
Fluent is throwing an error
Hi,
My environment:
My Package.swift
:
import PackageDescription
let package = Package(
name: "ItWorks-Sqlite",
targets: [
Target(name: "App"),
Target(name: "Run", dependencies: ["App"]),
],
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
.Package(url: "https://github.com/vapor/fluent-provider.git", majorVersion: 1),
],
exclude: [
"Config",
"Database",
"Localization",
"Public",
"Resources",
]
)
My output:
# vapor build
Building Project [Failed]
Command:
build --enable-prefetching
Error (1):
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /usr/bin/swift-build-tool -f /vapor/ItWorks-Sqlite/.build/debug.yaml
Output:
Linking ./.build/debug/Run
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'pthread_mutexattr_destroy'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'pthread_mutexattr_init'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'pthread_create'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'dlsym'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'dlerror'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'pthread_mutex_trylock'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'dlclose'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'pthread_mutexattr_settype'
/vapor/ItWorks-Sqlite/.build/debug/libCSQLite.so: error: undefined reference to 'dlopen'
clang: error: linker command failed with exit code 1 (use -v to see invocation)
<unknown>:0: error: link command failed with exit code 1 (use -v to see invocation)
Toolchain:
/usr/bin/swift
Help:
Join our Slack where hundreds of contributors
are waiting to help: http://vapor.team
Error: Build failed.
{
"idType": "uuid"
}
Not working on Config/fluent.json
, but if I set in the model or for drop.database.idType
it works fine.
http://beta.docs.vapor.codes/fluent/model/#id-type
Package.swift:
let package = Package(
name: "test-vapor",
dependencies: [
.Package(url: "https://github.com/vapor/vapor.git", majorVersion: 2),
.Package(url: "https://github.com/vapor/fluent-provider.git", majorVersion: 1)
],
exclude: [
"Config",
"Database",
"Localization",
"Public",
"Resources",
]
)
Running vapor build --clean
returns the error:
Cleaning [Done]
No .build folder, fetch may take a while...
Fetching Dependencies [Failed]
Error: swift-package: error: unsatisfiable
The warning If you want to use models with Fluent, make sure to add the model to the Droplet's preparations array, e.g., drop.preparations += ModelType.self
is useful for detecting misconfigured projects, except for the recommended fix is invalid swift. It should be updated to either drop.preparations.append(ModelType.self)
or use an array of preparations.
Here's the line of code: https://github.com/vapor/fluent-provider/blob/3c2cb5cf3c0b9cb387f65f8df410e927815985f5/Sources/FluentProvider/Provider.swift#L161
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.