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

Change Connection API to be synchronous #61

Open
irar2 opened this issue Mar 2, 2017 · 8 comments
Open

Change Connection API to be synchronous #61

irar2 opened this issue Mar 2, 2017 · 8 comments

Comments

@irar2
Copy link
Contributor

irar2 commented Mar 2, 2017

The execute query functions will look like this:

   /// Execute a query.
   ///
   /// - Parameter query: The query to execute. 
   /// - Returns: An instance of QueryResult representing the result of the query execution.
  func execute(query: Query) -> QueryResult

Transaction related functions will be changed in the same way:

    /// Start a transaction.
    ///
    /// - Returns:  An instance of QueryResult representing the result of the execution of start transaction command.
    func startTransaction() -> QueryResult

We can also throw errors instead of returning them inside QueryResult.


ResultFetcher will be synchronous only, i.e.

    /// Fetch the next row of the query result. This function is non-blocking.
    ///
    /// - Parameter callback: A callback to call when the next row of the query result is ready.
    func fetchNext(callback: ([Any?]?) ->())

will be removed.

@na-gupta
Copy link
Contributor

na-gupta commented Mar 2, 2017

@shmuelk mentioned you were thinking about making Kuery functions throw instead of returning QueryResult.error(). IMO, that would be better. (I just saw that you also mentioned this a possibility above)

Also, if we were to do that, I think it would be worth considering moving rows and titles from ResultSet into QueryResult as optionals and removing ResultSet entirely. Then QueryResult could be as simple as:

public class QueryResult {
    private let resultFetcher: ResultFetcher?

    // number of rows affected by a INSERT/UPDATE/DELETE or
    // number of rows returned by a SELECT (may be -1 if we fetch the result set iteratively)
    public let affectedRows: Int
    public let columnNames: [String]?
    public let resultSet: RowSequence?
    public lazy var rows: [[String: Any?]]? = {
        ...
    }()
}

What do you think?

@irar2
Copy link
Contributor Author

irar2 commented Mar 5, 2017

OK, we can do this.

@shmuelk proposed to use numberOfAffectedRows instead of affectedRows, titles instead of columnNames (because these don't have to be table columns), and rowSequence instead of resultSet.

@GiacomoLeopizzi
Copy link

GiacomoLeopizzi commented Jun 18, 2017

@irar2 Hello :),
Is it possible to know when the synchronous api will be released?
Many thanks!

@acaland
Copy link

acaland commented Jun 18, 2017

Hi @irar2,

Having the syncronous API will be great!
Thank you in advance

@ndPPPhz
Copy link

ndPPPhz commented Jun 18, 2017

@irar2 I was reading at the implementation of the MySQL plugin and I didn't find asynchronous call to the database, so actually I was wondering why do you decide to use completion handler instead of simple return and catch ?

@SMartorelli
Copy link

@shmuelk Would be amazing to have a synchronous API

@kilnerm
Copy link
Contributor

kilnerm commented Sep 5, 2018

This item will be addressed by PR #152

@kilnerm kilnerm self-assigned this Sep 5, 2018
@kilnerm
Copy link
Contributor

kilnerm commented Nov 14, 2018

We no longer plan on addressing this via the changes related to PR #152.

We will however look at providing a utility function to wrap the asynchronous API which will allow synchronous usage of the SwiftKuery API.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants