-
Notifications
You must be signed in to change notification settings - Fork 19
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
share open connection #28
Comments
This is a general programming question that gets into object-oriented design. So you might want to consult Apple's Swift tutorial or other resources on the web. There are many approaches to do what you want. Here is one way:
|
Thank you for answer. I will try to ask differently. |
I tried use struct, but still I have problem with declare conn - Value of type '[conn]' has no member 'prepareStatement' import UIKit struct conn { class ViewController: UIViewController {
|
Uff, try myconnection[0].conn.prepareStatement(text: text).execute() |
I'm sorry, my problem is still not resolved. My function start() opens session in Postgres database and I need to make this session still open. I checked the function prepareStatement, where is written "Any previous |
Please keep the discussion in this issue, rather than opening a new issue. |
Here is my understanding of what you want to do: You want to create a connection, and then be able to use that connection in various places in your application. Here is a simple way to do this:
With this simple approach, you need to ensure that only one thread uses the connection at a time, and you need to handle the connection dying, for example because of a transient network issue. Here is a more sophisticated approach: https://github.com/pitfield/PostgresClientKit-iOS-Example This uses a ConnectionPool. The README describes the benefits of doing this. |
Thank you so much for the solution!! |
Hi there,
in my swift project I call an example right at the beginning:
do {
var configuration = PostgresClientKit.ConnectionConfiguration()
configuration.host = "127.0.0.1"
configuration.database = "example"
configuration.user = "bob"
configuration.credential = .scramSHA256(password: "welcome1")
} catch {
print(error)
}
I need the connection not to be terminated and continue in another function:
func test() {
do {
let text = "SELECT * FROM foo();"
try connection.prepareStatement(text: text).execute(). // error: Cannot find 'connection' in scope
} catch {
print(error)
}
My problem: I don't know how set "connection" as global var
Can you please advise me how to solve this?
The text was updated successfully, but these errors were encountered: