1 /*
2  * Copyright (C) 2017 Julien Viet
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.SqlResult;
19 
20 import hunt.collection.List;
21 
22 import std.variant;
23 
24 /**
25  * Represents the result of an operation on database.
26  * @param <T>
27  */
28 interface SqlResult(T) {
29 
30     /**
31      * Get the number of the affected rows in the operation to this PgResult.
32      * <p/>
33      * The meaning depends on the executed statement:
34      * <ul>
35      *   <li>INSERT: the number of rows inserted</li>
36      *   <li>DELETE: the number of rows deleted</li>
37      *   <li>UPDATE: the number of rows updated</li>
38      *   <li>SELECT: the number of rows retrieved</li>
39      * </ul>
40      *
41      * @return the count of affected rows.
42      */
43     int rowCount();
44 
45     /**
46      * Get the names of columns in the PgResult.
47      *
48      * @return the list of names of columns.
49      */
50     string[] columnsNames();
51 
52     /**
53      * Get the number of rows in the PgResult.
54      *
55      * @return the count of rows.
56      */
57     int size();
58 
59     /**
60      * Get the result value.
61      *
62      * @return the result
63      */
64     T value();
65 
66     /**
67      * Get the property with the specified {@link PropertyKind}.
68      *
69      * @param propertyKind the kind of the property
70      * @return the value of the property
71      */
72     Variant property(string key);
73 
74     /**
75      * Return the next available result or {@code null}, e.g for a simple query that executed multiple queries or for
76      * a batch result.
77      *
78      * @return the next available result or {@code null} if none is available
79      */
80     SqlResult!(T) next();
81 
82     string toString();
83 }