Swiftpack.co - Package - vapor/fluent-kit

Github

link
Stars: 57

Used By

Total: 0

Releases

Require value for @Parent when eager loaded - 2020-08-27 20:00:50

This patch was authored and released by @tanner0101.

Queries that fail to eager-load a value for a @Parent relation will now throw an error (#380).

This change helps prevent unintended access of uninitialized @Parent properties in cases where no parent is found. For example, if the parent is deleted (including soft-deletion) or the reference was set to an invalid identifier.

Minimum iOS version is 13 - 2020-08-21 21:42:55

This patch was authored and released by @calebkleveter.

The minimum iOS version supported by this package is now iOS 13 since ISO8601DateFormatter requires it to be version 10 and 13 matches the Catalina requirement.

Support disabling foreign key checks in benchmarker - 2020-08-06 20:43:35

This patch was authored by @valeriomazzeo and released by @tanner0101.

Adds flag for disabling foreign key checks in FluentBenchmarker (#368).

In #364 testSchema_fieldReference has been introduced. Drivers like mongo don't support foreign key constraints which causes the above FluentBenchmark test to fail.

Although, an effort has been made to partially supports Fluent schema features by using mongo schema validation this specific feature it's still not supported.

Add raw query model decode helper - 2020-08-06 20:16:52

This patch was authored and released by @tanner0101.

Adds helper methods to SQLRow and SQLDatabase query builders for decoding models (#362, fixes #334).

guard let sql = req.db as? SQLDatabase else { ... }
let users = sql.raw("SELECT * FROM users").all(decoding: User.self)

Both first and all are available on SQLDatabase as well as decode on SQLRow.

let row: SQLRow = ...
let user = try row.decode(model: User.self)

These overloads work by circumventing model's Codable conformance and decoding the SQL row as database output.

Note: Some features of Model, like model.joined(_:), may not work correctly when decoding from SQLKit directly as they rely on specific key naming.

Add SQLConverterDelegate.beforeConvert method - 2020-07-29 01:27:37

This patch was authored and released by @tanner0101.

Adds SQLConverterDelegate.beforeConvert method (#364).

This is mostly an internal change and allows for SQLConverterDelegate conformers to alter the DatabaseSchema before it is converted to SQLKit expressions.

Additionally, a FluentBenchmarker test has been added to ensure that the .references field constraint is being enforced by drivers.

Simplify benchmark pooling + CI - 2020-07-23 19:17:28

This patch was authored and released by @tanner0101.

Internal changes only. Simplifies benchmark test pooling and CI (#361).

Support @Enum usage in QueryBuilder.set - 2020-07-22 16:46:30

This patch was authored and released by @tanner0101.

Fixes an issue causing QueryBuilder.set to improperly bind @Enum values (#360, fixes #357).

Add join methods for @Parent, @Children, and @Siblings - 2020-07-22 14:55:34

This patch was authored by @MatsMoll and released by @tanner0101.

Adds new methods to QueryBuilder for easily joining @Parent, @Children, and @Siblings relations. (#338)

Planet.query(on: db)
   // Joins the Star table
    .join(parent: \.$star)
   // Joins the Galaxy table based based on the joined Star table
    .join(from: Star.self, parent: \.$galaxy)
    .filter(Galaxy.self, \.$id == galaxyID)
    .unique()
   // Returns all Planet's in the galaxy with id `galaxyID`
    .all()

Test benchmark updates - 2020-07-17 23:35:49

This patch was authored and released by @tanner0101.

FluentBenchmarker now logs test names at .notice and siblings performance tests use a single connection (#356).

Add QueryBuilder.fields(for: Model) - 2020-07-15 17:31:09

This patch was authored and released by @tanner0101.

Adds a new method to QueryBuilder for fetching all fields from a given model (#354, fixes #346).

// Fetch all Planets with Star named "Sun"
let planets = Planet.query(on: req.db)
    // Only fetch fields for Planet, even though
    // Star is being joined. 
    .fields(for: Planet.self)
    // Join Star model and use it to filter results.
    .join(Star.self, on: \Planet.$star.$id == \Star.$id)
    .filter(Star.self, \.$name == "Sun")
    .all()

Fix @ID generation for nil values - 2020-07-15 13:40:16

This patch was authored and released by @tanner0101.

Fixes an issue causing .database generated @IDs to not generate values when set to nil (#353).

This issue was caused by changes in 1.3.2 (#352). FluentBenchmarker has been updated with a test that should catch this bug going forward.

Allow generated @IDs to be overridden - 2020-07-14 19:58:48

This patch was authored and released by @tanner0101.

Fixes a bug preventing @ID properties generated by .database (i.e., Int type) from being overridden (#352, fixes #332).

Fix invalid @Enum value decode - 2020-07-14 18:54:43

This patch was authored and released by @tanner0101.

Decoding a model with invalid @Enum or @OptionalEnum values now throws an error instead of crashing (#351, fixes #350).

Add @Timestamp(key: "...", on: .none) functionality - 2020-07-14 18:37:36

This patch was authored by @gwynne and released by @tanner0101.

Adds new case .none to TimestampTrigger (#336).

Using TimestampTrigger.none on a @Timestamp property makes it act like a normal @OptionalField, so that Fluent never updates the timestamp automatically. Such properties retain the ability to take advantage of TimestampFormats for explicitly defining the format of the timestamp value in the database.

Note: Technically, since this adds an enum case, it would be a semver-major change, breaking source compatibility for anyone switching over the TimestampTrigger type. However, the expectation is doing this would be very rare.

Fix optional string contains operator - 2020-07-14 17:25:13

This patch was authored and released by @tanner0101.

Fixes SQL conversion for the ~~ operator when used with optional fields (fixes #329).

add Database.logging(to:) method - 2020-07-13 16:21:34

This patch was authored and released by @tanner0101.

Adds a new extension to Database for overriding its logger (fixes #344, #345).

The example below shows how this API could be used to temporarily prevent errors from being logged.

app.post("users") { req in 
    let user: User = ...
    // Make a copy of the request logger
    // and change its log level
    var copy = req.logger
    copy.logLevel = .critical

    // Use the logging(to:) method to create a 
    // temporary Database with the new logger
    return user.save(
        on: req.db.logging(to: copy)
    )
}

Add missing join filter overload - 2020-07-10 18:06:03

This patch was authored and released by @tanner0101.

Adds a missing overload for filtering joined models (#342, fixes #310).

Adds method for appending models to ArrayTestDatabase (#342).

Disallows private-scoped migrations with default names. - 2020-07-06 16:33:46

This patch was authored and released by @mattpolzin.

Migrations with unstable names can no longer be applied (fixes #327).

Migrations with private scope and a default name will result in a fatal error now. If you run into this fatal error, there are two solutions:

  1. Make the migration public or internal.
  2. Give the migration an explicit name:
struct example: Migration {
    let name: String = "SomeUniqueNameHere"
    ...
}

Allow custom decimal type in tests - 2020-06-25 16:33:25

This patch was authored and released by @tanner0101.

Allows Fluent drivers to specify a custom data type for storing Decimal in Fluent's benchmark (#340, fixes #307).

benchmarker.testPerformance(decimalType: .dictionary)

Fix nil @Parent / @OptionalParent eager load - 2020-06-19 18:07:12

This patch was authored and released by @tanner0101.

Fixes an issue causing nested eager loading through an @Parent or @OptionalParent relation with all nil values to crash (#337, fixes #308).

FluentKit 1.0.0 - 2020-06-13 02:28:55

Docs: https://docs.vapor.codes/4.0/fluent/overview/ https://docs.vapor.codes/4.0/fluent/model/ https://docs.vapor.codes/4.0/fluent/relations/ https://docs.vapor.codes/4.0/fluent/migration/ https://docs.vapor.codes/4.0/fluent/query/ https://docs.vapor.codes/4.0/fluent/schema/ https://docs.vapor.codes/4.0/fluent/advanced/

More information on Vapor 4 official release: https://forums.swift.org/t/vapor-4-official-release-begins/34802

Add optional string contains operators - 2020-06-13 02:17:01

This patch was authored and released by @tanner0101.

Adds missing string contains operators for @OptionalField (#305).

Fully qualified Migration names - 2020-06-13 01:31:04

This patch was authored by @mattpolzin and released by @tanner0101.

Migration logs now use fully qualified Swift type names (#323, #319, fixes #318).

Migration names are now distinct from each other even if they have the same type name in different scopes.

Take the following example:

extension Foo {
    struct CreateMigration: Migration { ... }
}

This migration will now use the name App.Foo.CreateMigration instead of just CreateMigration as it did previously.

This prevents the migration name from clashing with a migration like:

extension Bar {
    struct CreateMigration: Migration { ... }
}

⚠️ This is a breaking change as migrations using the default name implementation will have different names than before. However, most users should not need to take action. Fluent will attempt to update old migration names in your database automatically to match the new default.

Add `.dictionary` data type - 2020-06-13 00:39:28

This patch was authored and released by @tanner0101.

Replaces the .json data type with .dictionary(of:) (#314)

This change more closely resembles existing .array type. The .json data type will continue to exist and forward to .dictionary. The dictionary data type now supports a value type for homogenous dictionaries. For example, [String: Int] would be .dictionary(of: .int).

Add input and output methods to Fields protocol - 2020-06-12 21:27:25

This patch was authored and released by @tanner0101.

Adds input(to:) and output(from:) methods to the Fields protocol (extended by Model) which allows them to be overridden (#320).

The input(to:) method is called when a model is being saved to the database. The output(from:) method is called when a model is being initialized from database output.

All model properties have input(to:) and output(from:) methods as a part of the AnyDatabaseProperty protocol.

final class Planet: Model {
    @ID(key: .id)
    var id: UUID?

    @Field(key: "name") 
    var name: String

    // Override output method.
    func output(from output: DatabaseOutput) throws {
        try self.$id.output(from: output)
        try self.$name.output(from: output)
        self.name = self.name.capitalized()
    }
}

Fix @Timestamp decode from missing key - 2020-06-04 22:45:47

This patch was authored and released by @tanner0101.

Fixes an issue causing @Timestmap properties to not decode as nil when their key was not present in the data (#313).

Add query history - 2020-06-03 20:24:27

This patch was authored and released by @mcdappdev.

Adds a QueryHistory object which is used to maintain a history of queries run against a Database. (#312)

Reduce query logging level - 2020-06-03 15:31:14

This patch was authored and released by @tanner0101.

QueryBuilder now logs queries at debug logging level (#311).

Previously queries were logged at info which crowded the log level.

Require SQLKit 3.1.0 - 2020-06-02 19:51:08

This patch was authored and released by @tanner0101.

The previous tag used new API added in SQLKit 3.1.0. This release bumps the version requirement for that package to prevent build errors if swift package update is not run.

Add helper methods for adding multiple Migrations at once - 2020-05-30 14:46:05

This patch was authored and released by @gwynne.
  • Adds an overload of Migrations.add(_:to:) which accepts an array of Migration, e.g.:

    app.migrations.add([ConfigModel.Migration(), SolarSystem.Migration()])
    app.migrations.add([UserModel.Migration(), PostModel.Migration()], to: .psql)
    

    As a new public API, this requires a semver-minor release.

  • Also adds an overload which accepts a variadic parameter of Migration type:

    app.migrations.add(ConfigModel.Migration(), SolarSystem.Migration())
    app.migrations.add(UserModel.Migration(), PostModel.Migration(), to: .psql)
    
  • Adds a benchmark test for the new methods, just for the heck of it.