Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
206 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
sql/src/main/kotlin/net/aquadc/persistence/sql/dialect/postgres.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
@file:JvmName("PostgresDialect") | ||
package net.aquadc.persistence.sql.dialect.postgres | ||
|
||
import net.aquadc.collections.enumMapOf | ||
import net.aquadc.persistence.sql.dialect.BaseDialect | ||
import net.aquadc.persistence.sql.dialect.Dialect | ||
import net.aquadc.persistence.type.DataType | ||
|
||
/** | ||
* Implements PostgreSQL [Dialect]. | ||
*/ | ||
@JvmField | ||
val PostgresDialect: Dialect = object : BaseDialect( | ||
enumMapOf( | ||
DataType.Simple.Kind.Bool, "bool", | ||
DataType.Simple.Kind.I32, "int", | ||
DataType.Simple.Kind.I64, "int8", | ||
DataType.Simple.Kind.F32, "real", | ||
DataType.Simple.Kind.F64, "float8", | ||
DataType.Simple.Kind.Str, "text", | ||
DataType.Simple.Kind.Blob, "bytea" | ||
), | ||
truncate = "TRUNCATE TABLE" | ||
) { | ||
override fun StringBuilder.appendPkType(type: DataType.Simple<*>, managed: Boolean): StringBuilder = | ||
if (managed) appendNameOf(type) | ||
else { // If PK column is 'managed', we just take `structToInsert[pkField]`. | ||
// Otherwise, its our responsibility to make PK auto-generated | ||
if (type.kind == DataType.Simple.Kind.I32) append("serial") | ||
else if (type.kind == DataType.Simple.Kind.I64) append("serial8") | ||
else throw UnsupportedOperationException() // wat? Boolean, float, double, string, byte[] primary key? O_o | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
sql/src/main/kotlin/net/aquadc/persistence/sql/dialect/sqlite.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
@file:JvmName("SqliteDialect") | ||
package net.aquadc.persistence.sql.dialect.sqlite | ||
|
||
import net.aquadc.collections.enumMapOf | ||
import net.aquadc.persistence.sql.dialect.BaseDialect | ||
import net.aquadc.persistence.sql.dialect.Dialect | ||
import net.aquadc.persistence.type.DataType | ||
|
||
/** | ||
* Implements SQLite [Dialect]. | ||
*/ | ||
// wannabe `@JvmField val` but this breaks compilation. Dafuq? | ||
object SqliteDialect : BaseDialect( | ||
enumMapOf( | ||
DataType.Simple.Kind.Bool, "INTEGER", | ||
DataType.Simple.Kind.I32, "INTEGER", | ||
DataType.Simple.Kind.I64, "INTEGER", | ||
DataType.Simple.Kind.F32, "REAL", | ||
DataType.Simple.Kind.F64, "REAL", | ||
DataType.Simple.Kind.Str, "TEXT", | ||
DataType.Simple.Kind.Blob, "BLOB" | ||
), | ||
truncate = "DELETE FROM" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.