pmurphyjam / SQLPackage

SQLPackage facilitates the use of SQLite using SQLDataAccess. One Swift Package does it all!
MIT License
0 stars 0 forks source link

Invalid SPM installation #1

Open dpw67 opened 2 years ago

dpw67 commented 2 years ago

Your installation instructions did not work when I tried to add SPMPackage as you describe in the README. It took me a little while to determine how to install it, especially since I could not find any of our packages in the Swift Package Index.

Currently, you show an obsolete GitHUB URL; it should use "https:" rather than "git:".

Event when I got the URL correct, then the Package.swift file also has dependencies for Willow and ObjectMapper with the same problem.

Until that is updated, I decided to first explicitly add the packages for Willow and ObjectMapper directly, and then SQLPackage could be added because its dependencies were found without trying to fetch them with the invalid URLs.

Also, your README code examples have not been updated to reflect the Willow logger, so all that code must be updated before it can be used.

If you expect anybody else to use this package, you must update your README and Package.swift with the correct information, as well as include it in Swift Package Index.

This initially looked like it might be worthwhile to consider for SQLite data access, but it ended up being much more work to make it work for me. So I will just stick with the SQLite.swift. Also I notice it has not be updated for a very long time, so perhaps it was just a personal package and really not ready for broader use.

pmurphyjam commented 2 years ago

Doug, It should work, I’ve been using it for years. Perhaps the documentation is good enough. It’s super fast and robust and doesn’t leak memory. So it requires ObjectMapper to work and this is in the SQLPackage requirements so it should pick it up. This maps your data you get from the DB back to your SQL Object.

You want to install SQLPackage as a Swift Package, so in Xcode Project you call this in Package Dependencies: SQLPackage 1.0.0 - New Major @. @.>:pmurphyjam/SQLPackage.git I get this as an SSH package

Then it should show up at the bottom of your Xcode Project as :

SQLPackage 1.1.28. //All in upper case, if it’s lower case it didn’t fetch it properly

There’s a sample example project that uses it called SQLiteDemo https://github.com/pmurphyjam/SQLiteDemo https://github.com/pmurphyjam/SQLiteDemo It uses a sample AppInfo.swift Object for SQLite You define your tables columns like this : I usually then import import Foundation import ObjectMapper import SQLDataAccess import Sqldb public struct UserObj: Codable,Sqldb,Mappable,Equatable,Hashable { //tableName required for tables in CueMate.db public var tableName: String? = “User"

public var id: Int64? = 0 More user vars here...

And you end the table definition with : //Optional sortAlpha default is false public var sortAlpha: Bool = false The above is required so the Sqldb doesn’t search past sortAlpha declaration

Now you need to create the Data Model for UserObj, call it UserModel public struct UserModel {

// MARK: - UserModel static public func insertUserSQL(_ obj:UserObj) -> Dictionary<String,Any> { //Here we let Sqldb create the SQL insert syntax for us let sqlParams = obj.getSQLInsert()! return sqlParams }

@discardableResult static public func insertUser(_ obj:UserObj) -> Bool
{
    let sqlParams = self.insertUserSQL(obj)
    let status = DataManager.dataAccess.executeStatement(sqlParams[SQL] as! String, withParams: sqlParams[PARAMS] as? Array<Any>)
    return status
}

static public func updateUserSQL(_ obj:UserObj) -> Dictionary<String,Any>
{
    //Here we let Sqldb create the SQL update syntax for us
    let sqlParams = obj.getSQLUpdate(whereItems:"id")!
    return sqlParams
}

@discardableResult static public func updateUser(_ obj:UserObj) -> Bool
{
    let sqlParams = self.updateUserSQL(obj)
    let status = DataManager.dataAccess.executeStatement(sqlParams[SQL] as! String, withParams: sqlParams[PARAMS] as? Array<Any>)
    return status
}
static public func insertUserValidSQL(_ obj:UserObj) -> Dictionary<String,Any>
{
    //Here we let Sqldb create the SQL insert syntax for us
    let sqlParams = obj.getSQLInsertValid()!
    return sqlParams
}

@discardableResult static public func insertUserValid(_ obj:UserObj) -> Bool
{
    let sqlParams = self.insertUserValidSQL(obj)
    let status = DataManager.dataAccess.executeStatement(sqlParams[SQL] as! String, withParams: sqlParams[PARAMS] as? Array<Any>)
    return status
}

static public func updateUserValidSQL(_ obj:UserObj) -> Dictionary<String,Any>
{
    //Here we let Sqldb create the SQL update syntax for us
    let sqlParams = obj.getSQLUpdateValid(whereItems:"id")!
    return sqlParams
}

@discardableResult static public func updateUserValid(_ obj:UserObj) -> Bool
{
    let sqlParams = self.updateUserValidSQL(obj)
    let status = DataManager.dataAccess.executeStatement(sqlParams[SQL] as! String, withParams: sqlParams[PARAMS] as? Array<Any>)
    return status
}

}

Then in ViewController.swift it includes DataManager and shows you how to consume it.

If you still have problems I can walk you through it perhaps via a Zoom call or something, let me know. Once you get it working you’ll be extremely satisfied with it, it’s easy to use and high performance. I use it for a Tennis App that creates like 20MBs of data per Session, and it literally reads a RestFul API to get 10 Sessions with each Session being around 10MBs and this takes like 30s to download from the Server.

Pat Murphy

On Aug 10, 2022, at 11:22 AM, Doug Warren @.***> wrote:

Your installation instructions did not work when I tried to add SPMPackage as you describe in the README. It took me a little while to determine how to install it, especially since I could not find any of our packages in the Swift Package Index.

Currently, you show an obsolete GitHUB URL; it should use "https:" rather than "git:".

Event when I got the URL correct, then the Package.swift file also has dependencies for Willow and ObjectMapper with the same problem.

Until that is updated, I decided to first explicitly add the packages for Willow and ObjectMapper directly, and then SQLPackage could be added because its dependencies were found without trying to fetch them with the invalid URLs.

Also, your README code examples have not been updated to reflect the Willow logger, so all that code must be updated before it can be used.

If you expect anybody else to use this package, you must update your README and Package.swift with the correct information, as well as include it in Swift Package Index.

This initially looked like it might be worthwhile to consider for SQLite data access, but it ended up being much more work to make it work for me. So I will just stick with the SQLite.swift. Also I notice it has not be updated for a very long time, so perhaps it was just a personal package and really not ready for broader use.

— Reply to this email directly, view it on GitHub https://github.com/pmurphyjam/SQLPackage/issues/1, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABAAGXLYURKJ7RQZXQMOFSDVYPXQDANCNFSM56FPRUXQ. You are receiving this because you are subscribed to this thread.