Skip to content
This repository has been archived by the owner on Aug 11, 2023. It is now read-only.

Releases: 0xLet/FLite

FLite.init

02 Oct 22:48
7e98b7d
Compare
Choose a tag to compare

FLite init

public init(
        configuration: SQLiteConfiguration = .init(storage: .memory),
        loggerLabel: String
    )

public init(
        eventGroup: EventLoopGroup,
        threadPool: NIOThreadPool,
        configuration: DatabaseConfigurationFactory,
        id: DatabaseID,
        logger: Logger
    )

public init(
        threads: Int,
        configuration: DatabaseConfigurationFactory,
        id: DatabaseID,
        logger: Logger
    )

Example Usage

var values = [Todo]()

try? FLite.memory.prepare(migration: Todo.self).wait()

try! FLite.memory.add(model: Todo(title: "Hello World", strings: ["hello", "world"])).wait()

FLite.memory.all(model: Todo.self)
    .whenSuccess { (todos) in
        values = todos
}

Persisted Data

var persist = FLite(configuration: .file("\(FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first?.path ?? "")/default.sqlite"), loggerLabel: "persisted-FLITE")

Example Model & Migration

import FluentSQLiteDriver

internal final class Todo: Model {
    init() { }
    
    static let schema: String = "todos"
    
    /// The unique identifier for this `Todo`.
    @ID(key: .id)
    var id: UUID?

    /// A title describing what this `Todo` entails.
    @Field(key: "title")
    var title: String
    
    @Field(key: "someList")
    var someList: [String]

    /// Creates a new `Todo`.
    init(id: UUID? = nil, title: String, strings: [String]) {
        self.id = id
        self.title = title
        self.someList = strings
    }
}

/// Allows `Todo` to be used as a dynamic migration.
extension Todo: Migration {
    func prepare(on database: Database) -> EventLoopFuture<Void> {
        database.schema(Todo.schema)
            .id()
            .field("title", .string, .required)
            .field("someList", .array(of: .string), .required)
            .create()
    }
    
    func revert(on database: Database) -> EventLoopFuture<Void> {
        database.schema(Todo.schema).delete()
    }
}

Vapor 4 Support

01 Sep 20:52
70eca7a
Compare
Choose a tag to compare
Merge pull request #21 from 0xLeif/develop

Develop

Vapor 4 Release

15 Jul 19:54
cb77116
Compare
Choose a tag to compare

Requires Xcode >= 11.5 and Swift 5.2

// Use FLite.main
//  Default Storage Type: Memory

try? FLite.prepare(migration: Todo.self).wait()

try! FLite.add(model: Todo(title: "Hello World", strings: ["hello", "world"])).wait()

FLite.fetch(model: Todo.self)
    .whenSuccess { (values) in
        print(values)
}

Vapor 3 Release

08 Jul 20:59
c1a85bb
Compare
Choose a tag to compare
FLite.storage = .memory

FLite.prepare(model: Todo.self)
        
FLite.create(model: Todo(title: "Hello World"))

FLite.fetch(model: Todo.self) { values in
    print(values)
}