RealmSwiftMacro

0.0.5

swift macro that aims to produce crud methods on Realm Object
fummicc1/RealmSwiftMacro

What's New

0.0.5

2023-09-13T13:40:35Z

Full Changelog: 0.0.4...0.0.5

RealmSwiftMacro

A macro that produces some methods that can help to perform crud on Realm database.

following code defines Todo object which represents simple data stored in Realm.

    @GenCrud
    class Todo: Object {
        @Persisted(primaryKey: true) var _id: ObjectId
        @Persisted var name: String
        @Persisted var owner: String
        @Persisted var status: String
    }

Adding @GenCrud macro to Object, crud methods will automatically generates and can be used like the below.

    // MARK: Create
    let todo = try await Todo.create(
        _id: .generate(),
        name: "Sample name",
        owner: "Sample owner",
        status: "Sample status"
    )
    // MARK: Update
    try await todo.update(name: "Updated name")
    // MARK: Delete
    try await todo.delete()
    // MARK: Get all List
    let todos = try await Todo.list()
    print(todos)
    // MARK: Observe all List
    let stream = try await Todo.observe()
    for try await todoChange in stream {
        switch todoChange {
        case .initial(let todos):
            print(todos)
        case let .update(updatedTodos, _, _, _):
            print(updatedTodos)
        case .error(let error):
            print(error)
        }
    }

Contributing

Pull requests, bug reports and feature requests are welcome 🚀

Description

  • Swift Tools
View More Packages from this Author

Dependencies

  • None
Last updated: Tue Nov 05 2024 23:03:57 GMT-1000 (Hawaii-Aleutian Standard Time)