Swiftpack.co - Package - nodes-vapor/sugar

Sugar 🍬

Swift Version Vapor Version Circle CI codebeat badge codecov Readme Score GitHub license

📦 Installation

Add Sugar to the package dependencies (in your Package.swift file):

dependencies: [
    ...,
    .package(url: "https://github.com/nodes-vapor/sugar.git", from: "4.0.0-beta")
]

as well as to your target (e.g. "App"):

targets: [
    ...
    .target(
        name: "App",
        dependencies: [... "Sugar" ...]
    ),
    ...
]

Getting started 🚀

Make sure that you've imported Sugar everywhere when needed:

import Sugar

Helpers

This package contains a lot of misc. functionality that might not fit into it's own package or that would best to get PR'ed into Vapor. Some examples of what this package contains:

Environment variables

Access environment variables by writing

env("my-key", "my-fallback-value")

Seeder commands

If you want to make your model seedable, you can conform it to Seedable and use SeederCommand to wrap your seedable model. This basically means that you can focus on how your model gets initialized when running your command, and save a little code on actually performing the database work.

Seeding multiple instances of your model will be added - feel free to PR.

Authentication

This package contains a lot of convenience related to JWT, usernames and passwords which is used in JWTKeychain and Admin Panel.

Migrations

Sugar contains a helper function for adding properties while excluding some specific ones. This makes it a bit more convenient if you want to only modify how a single one or a couple of fields gets prepared.

extension MyModel: Migration {
    static func prepare(on connection: MySQLConnection) -> Future<Void> {
        return MySQLDatabase.create(self, on: connection) { builder in
            try addProperties(to: builder, excluding: [\.title])
            builder.field(for: \.title, type: .varchar(191))
        }
    }
}

🏆 Credits

This package is developed and maintained by the Vapor team at Nodes. The package owner for this project is Siemen.

📄 License

This package is open-sourced software licensed under the MIT license

Github

link
Stars: 22
Help us keep the lights on

Releases

4.0.0-rc.4 - May 14, 2019

Added

  • Less constraints on Loginable

4.0.0-rc.3 - May 7, 2019

Fixed

  • Fixed Swift 5 compiler warnings related to redundant access modifiers

4.0.0-rc.2 - Mar 23, 2019

Changed

  • Loosen default implementation for Creatable's init

4.0.0-rc.1 - Mar 6, 2019

Added

  • applyUpdate on Future<Updatable>

Removed

  • overload of Future.flatTry that takes a closure returning Future<Any> was removed. Use the one that takes a closure retuning Future<Void> instead. This removal helps with type inference and the Any version did not add any convenience since a .map { $0 as Any } was needed which is not better than .transform(()).

4.0.0-beta.2 - Feb 17, 2019

Added

  • Add requireParameterCount(upTo:) on TagContext to check if there are at most n parameters (extracted from the nodes-vapor/Bootstrap package).