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.base.SqlClient; 19 20 import hunt.database.base.AsyncResult; 21 import hunt.database.base.Common; 22 import hunt.database.base.RowSet; 23 import hunt.database.base.Tuple; 24 25 import hunt.collection.List; 26 import hunt.concurrency.Future; 27 28 29 /** 30 * Defines the client operations with a database server. 31 * 32 * @author <a href="mailto:julien@julienviet.com">Julien Viet</a> 33 */ 34 interface SqlClient { 35 36 /** 37 * Execute a simple query. 38 * 39 * @param sql the query SQL 40 * @param handler the handler notified with the execution result 41 * @return a reference to this, so the API can be used fluently 42 */ 43 SqlClient query(string sql, RowSetHandler handler); 44 45 Future!RowSet queryAsync(string sql); 46 47 RowSet query(string sql); 48 49 /** 50 * Execute a simple query. 51 * 52 * @param sql the query SQL 53 * @param collector the collector 54 * @param handler the handler notified with the execution result 55 * @return a reference to this, so the API can be used fluently 56 */ 57 // <R> SqlClient query(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 58 59 /** 60 * Prepare and execute a query. 61 * 62 * @param sql the prepared query SQL 63 * @param handler the handler notified with the execution result 64 * @return a reference to this, so the API can be used fluently 65 */ 66 SqlClient preparedQuery(string sql, RowSetHandler handler); 67 68 /** 69 * Prepare and execute a query. 70 * 71 * @param sql the prepared query SQL 72 * @param collector the collector 73 * @param handler the handler notified with the execution result 74 * @return a reference to this, so the API can be used fluently 75 */ 76 // <R> SqlClient preparedQuery(string sql, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 77 78 /** 79 * Prepare and execute a query. 80 * 81 * @param sql the prepared query SQL 82 * @param arguments the list of arguments 83 * @param handler the handler notified with the execution result 84 * @return a reference to this, so the API can be used fluently 85 */ 86 SqlClient preparedQuery(string sql, Tuple arguments, RowSetHandler handler); 87 88 /** 89 * Prepare and execute a query. 90 * 91 * @param sql the prepared query SQL 92 * @param arguments the list of arguments 93 * @param collector the collector 94 * @param handler the handler notified with the execution result 95 * @return a reference to this, so the API can be used fluently 96 */ 97 // <R> SqlClient preparedQuery(string sql, Tuple arguments, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 98 99 /** 100 * Prepare and execute a createBatch. 101 * 102 * @param sql the prepared query SQL 103 * @param batch the batch of tuples 104 * @param handler the handler notified with the execution result 105 * @return a reference to this, so the API can be used fluently 106 */ 107 SqlClient preparedBatch(string sql, List!(Tuple) batch, RowSetHandler handler); 108 109 /** 110 * Prepare and execute a createBatch. 111 * 112 * @param sql the prepared query SQL 113 * @param batch the batch of tuples 114 * @param collector the collector 115 * @param handler the handler notified with the execution result 116 * @return a reference to this, so the API can be used fluently 117 */ 118 // <R> SqlClient preparedBatch(string sql, List!(Tuple) batch, Collector<Row, ?, R> collector, Handler!(AsyncResult!(SqlResult!(R))) handler); 119 120 /** 121 * Close the client and release the associated resources. 122 */ 123 void close(); 124 125 }