Skip to content

Instantly share code, notes, and snippets.

@kylebrowning kylebrowning/Device.swift Secret
Created Feb 7, 2019

What would you like to do?
A quick APNS Device
import FluentSQLite
import Vapor
/// A single entry of a Device list.
final class Device: SQLiteModel {
/// The unique identifier for this `Device`.
var id: Int?
/// A deviceToken specific to this `Device`
var deviceToken: String
/// A platform inidicator, ios, or android
var platform: String
/// Creates a new `Device`.
init(id: Int? = nil, deviceToken: String, platform: String) { = id
self.deviceToken = deviceToken
self.platform = platform
/// Allows `Device` to be used as a dynamic migration.
extension Device: Migration { }
/// Allows `Device` to be encoded to and decoded from HTTP messages.
extension Device: Content { }
/// Allows `Device` to be used as a dynamic parameter in route definitions.
extension Device: Parameter { }
extension Device: SQLiteMigration {
static func prepare(on conn: SQLiteConnection) -> Future<Void> {
return Database.create(self, on: conn) { builder in
try addProperties(to: builder)
builder.unique(on: \.deviceToken)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.