1 /* 2 * Copyright (C) 2019, HuntLabs 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 * 16 */ 17 18 module hunt.database.driver.postgresql.PostgreSQLConnection; 19 20 import hunt.database.driver.postgresql.PostgreSQLNotification; 21 import hunt.database.driver.postgresql.impl.PostgreSQLConnectionImpl; 22 23 import hunt.database.base.Common; 24 import hunt.database.base.PreparedQuery; 25 import hunt.database.base.SqlResult; 26 import hunt.database.base.RowSet; 27 import hunt.database.base.Row; 28 import hunt.database.base.SqlConnection; 29 import hunt.database.base.Tuple; 30 31 import hunt.collection.List; 32 33 /** 34 * A connection to Postgres. 35 * 36 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> 37 * @author <a href="mailto:emad.albloushi@gmail.com">Emad Alblueshi</a> 38 */ 39 interface PgConnection : SqlConnection { // 40 41 /** 42 * Connects to the database and returns the connection if that succeeds. 43 * <p/> 44 * The connection interracts directly with the database is not a proxy, so closing the 45 * connection will close the underlying connection to the database. 46 * 47 * @param vertx the vertx instance 48 * @param options the connect options 49 * @param handler the handler called with the connection or the failure 50 */ 51 // static void connect(Vertx vertx, PgConnectOptions options, Handler!(AsyncResult!(PgConnection)) handler) { 52 // PgConnectionImpl.connect(vertx, options, handler); 53 // } 54 55 /** 56 * Like {@link #connect(Vertx, PgConnectOptions, Handler)} with options build from the environment variables. 57 */ 58 // static void connect(Vertx vertx, Handler!(AsyncResult!(PgConnection)) handler) { 59 // connect(vertx, PgConnectOptions.fromEnv(), handler); 60 // } 61 62 /** 63 * Like {@link #connect(Vertx, PgConnectOptions, Handler)} with options build from {@code connectionUri}. 64 */ 65 // static void connect(Vertx vertx, string connectionUri, Handler!(AsyncResult!(PgConnection)) handler) { 66 // connect(vertx, PgConnectOptions.fromUri(connectionUri), handler); 67 // } 68 69 /** 70 * Set an handler called when the connection receives notification on a channel. 71 * <p/> 72 * The handler is called with the {@link PgNotification} and has access to the channel name 73 * and the notification payload. 74 * 75 * @param handler the handler 76 * @return the transaction instance 77 */ 78 PgConnection notificationHandler(PgNotificationHandler handler); 79 80 /** 81 * Send a request cancellation message to tell the server to cancel processing request in this connection. 82 * <br>Note: Use this with caution because the cancellation signal may or may not have any effect. 83 * 84 * @param handler the handler notified if cancelling request is sent 85 * @return a reference to this, so the API can be used fluently 86 */ 87 PgConnection cancelRequest(VoidHandler handler); 88 89 /** 90 * @return The process ID of the target backend 91 */ 92 int processId(); 93 94 /** 95 * @return The secret key for the target backend 96 */ 97 int secretKey(); 98 99 // PgConnection prepare(string sql, PreparedQueryHandler handler); 100 // PgConnection exceptionHandler(ExceptionHandler handler); 101 // PgConnection closeHandler(VoidHandler handler); 102 // PgConnection preparedQuery(string sql, RowSetHandler handler); 103 104 105 // <R> PgConnection preparedQuery(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 106 // PgConnection query(string sql, RowSetHandler handler); 107 108 109 // <R> PgConnection query(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 110 // PgConnection preparedQuery(string sql, Tuple arguments, RowSetHandler handler); 111 112 113 // <R> PgConnection preparedQuery(string sql, Tuple arguments, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 114 // PgConnection preparedBatch(string sql, List!(Tuple) batch, RowSetHandler handler); 115 116 117 // <R> PgConnection preparedBatch(string sql, List!(Tuple) batch, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 118 }