-
Notifications
You must be signed in to change notification settings - Fork 10
/
Dialect.kt
79 lines (64 loc) · 2.45 KB
/
Dialect.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package net.aquadc.persistence.sql.dialect
import net.aquadc.persistence.struct.Schema
import net.aquadc.persistence.sql.Order
import net.aquadc.persistence.sql.Table
import net.aquadc.persistence.sql.WhereCondition
import net.aquadc.persistence.type.DataType
/**
* Represents an SQL dialect. Provides functions for building queries.
*/
interface Dialect {
/**
* Constructs an `INSERT INTO <table> (<col>, <col>, ...) VALUES (?, ?, ...)` SQL query
*/
fun <SCH : Schema<SCH>> insert(table: Table<SCH, *>): String
/**
* Constructs an SQL query like `SELECT <col> from <table> WHERE <condition>`
*/
fun <SCH : Schema<SCH>> selectQuery(
table: Table<SCH, *>, columns: Array<out CharSequence>,
condition: WhereCondition<SCH>, order: Array<out Order<SCH>>
): String
/**
* Constructs an SQL query like `SELECT COUNT(*) from <table> WHERE <condition>`
*/
fun <SCH : Schema<SCH>> selectCountQuery(table: Table<SCH, *>, condition: WhereCondition<SCH>): String
/**
* Appends WHERE clause (without WHERE itself) to [this] builder.
*/
@Deprecated("unused by Session")
fun <SCH : Schema<SCH>> StringBuilder.appendWhereClause(context: Table<SCH, *>, condition: WhereCondition<SCH>): StringBuilder
/**
* Appends ORDER clause (without ORDER BY itself) to [this] builder.
* @param order must be non-empty
*/
fun <SCH : Schema<SCH>> StringBuilder.appendOrderClause(schema: SCH, order: Array<out Order<SCH>>): StringBuilder
/**
* Constructs an SQL query like `UPDATE <table> SET <col> = ?`
*/
fun <SCH : Schema<SCH>> updateQuery(table: Table<SCH, *>, cols: Array<out CharSequence>): String
/**
* Constructs an SQL query like `DELETE FROM <table> WHERE <idCol> = ?`
*/
fun deleteRecordQuery(table: Table<*, *>): String
/**
* Appends quoted and escaped table or column name.
*/
fun StringBuilder.appendName(name: CharSequence): StringBuilder
/**
* Returns an SQL query to create the given [table].
*/
fun createTable(table: Table<*, *>, temporary: Boolean = false): String
/**
* Returns `TRUNCATE` query to clear the whole table.
*/
fun truncate(table: Table<*, *>): String
/**
* Whether database has support for arrays.
*/
val hasArraySupport: Boolean
/**
* Figures out simple name of a primitive type.
*/
fun nameOf(kind: DataType.NotNull.Simple.Kind): String
}