Skip to content

AcademyIFCE/nuvem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

79 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Nuvem

Declaring Models

struct User: CKModel {
    
    var record: CKRecord!
    
    @CKField("name")
    var name: String
    
    init() { }
    
}

struct Todo: CKModel {
    
    var record: CKRecord!
    
    @CKTimestamp(.creation)
    var creationDate: Date?
    
    @CKTimestamp(.modification)
    var modificationDate: Date?
    
    @CKField("text")
    var text: String
    
    @CKField("tags", default: [])
    var tags: [String]
    
    @CKField("isCompleted")
    var isCompleted: Bool
    
    @CKReferenceField("user")
    var user: User?
    
    init() { }
    
}

Saving

try await todo.save(on: <#CKDatabase#>)

Deleting

try await todo.delete(on: <#CKDatabase#>)

Querying

try await Todo.query(on: <#CKDatabase#>).all()

try await Todo.query(on: <#CKDatabase#>).first()

try await Todo.query(on: <#CKDatabase#>).limit(10)

Filtering

try await Todo.query(on: <#CKDatabase#>).filter(\.$isCompleted == true).all()

Sorting

try await Todo.query(on: <#CKDatabase#>).sort(\.$modificationDate, order: .descending).all()

Specifying Desired Fields

try await Todo.query(on: <#CKDatabase#>).field(\.$text, \.$isCompleted, \.$user).all()

Eager Loading Reference

try await Todo.query(on: <#CKDatabase#>).with(\.$user).all()

Putting It All Together

let todos = try await Todo.query(on: <#CKDatabase#>)
    .filter(\.$isCompleted == true)
    .sort(\.$modificationDate, order: .descending)
    .field(\.$text, \.$isCompleted, \.$user)
    .with(\.$user)
    .all()

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages