Skip to content

Commit

Permalink
Add query methods
Browse files Browse the repository at this point in the history
  • Loading branch information
enums committed Jul 4, 2019
1 parent bbe13b0 commit 83f8586
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Source/Pjango/Model/PCModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ open class PCModel: PCObject, PCViewable {
return nil
}

open class func queryObjects(ext: (useCache: Bool, param: String)? = nil) -> [PCModel]? {

open class func queryObjects<T>(field: PCDataBaseField, likeValue value: PCModelDataBaseFieldType, useCache: Bool = true, ext: String = "") -> [T]? {
return queryObjects(ext: (useCache, "WHERE \(field.name) like '\(value)' \(ext)"))
}

open class func queryObjects<T>(field: PCDataBaseField, equalValue value: PCModelDataBaseFieldType, useCache: Bool = true, ext: String = "") -> [T]? {
return queryObjects(ext: (useCache, "WHERE \(field.name)='\(value)' \(ext)"))
}

open class func queryObjects<T>(ext: (useCache: Bool, param: String)? = nil) -> [T]? {
guard let meta = PjangoRuntime._pjango_runtime_models_name2meta[_pjango_core_class_name] else {
return nil
}
Expand Down Expand Up @@ -122,10 +131,9 @@ open class PCModel: PCObject, PCViewable {
for i in 0..<record.count {
model._pjango_core_model_set_field_data(index: i, value: record[i] as Any)
}
return model
return model as? T
}
}

@discardableResult
open class func insertObject(_ model: PCModel) -> Bool {
if PjangoRuntime._pjango_runtime_database.insertModel(model) == true {
Expand Down

0 comments on commit 83f8586

Please sign in to comment.