Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to generate raw API that throws (vs returning the error code) #35

Open
helje5 opened this issue Oct 18, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@helje5
Copy link
Member

helje5 commented Oct 18, 2024

There was a request to generate raw API that throws vs returning the SQLite error code.

E.g. instead of:

func sqlite3_person_insert(_ db: OpaquePointer!, _ record: inout Person)
  -> Int32

this:

func sqlite3_person_insert(_ db: OpaquePointer!, _ record: inout Person) throws

Even in raw mode Enlighter already generates a nested SQLError structure into the Database structure, which could be used in the throwing versions:

public struct Database {
  public struct SQLError : Swift.Error, Equatable {
    public let code : Int32
    public let message : String?

Documented here: https://lighter-swift.github.io/documentation/lighter/sqliteapi#Handling-Errors

Notably there are raw functions that currently return nil on error and expect the caller to check the db handle for errors on its own. E.g.:

public func sqlite3_people_fetch(
  _ db: OpaquePointer!,
  sql customSQL: String? = nil,
  orderBy orderBySQL: String? = nil,
  limit: Int? = nil
) -> [ Person ]?
{
...
  guard sqlite3_prepare_v2(db, sql, -1, &handle, nil) == SQLITE_OK,
        let statement = handle else { return nil }
...
    else if rc != SQLITE_ROW {
      return nil
    }

I don't think this is very "hard" to add, but it affects quite a lot of code, i.e. it is quite a bit of work :-)

Created a feature/throwing-raw-1 that adds the option and an insert generator that does sth.

@helje5 helje5 added the enhancement New feature or request label Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant