Initial Development #1
@ -23,13 +23,12 @@ object Parameters:
|
|||||||
def nameFields(fields: Seq[Field[?]]): Seq[Field[?]] =
|
def nameFields(fields: Seq[Field[?]]): Seq[Field[?]] =
|
||||||
val name = ParameterName()
|
val name = ParameterName()
|
||||||
fields.map { it =>
|
fields.map { it =>
|
||||||
if ((it.getParameterName == null || it.getParameterName.isEmpty)
|
if (it.getParameterName == null || it.getParameterName.isEmpty)
|
||||||
&& !(Op.EXISTS :: Op.NOT_EXISTS :: Nil).contains(it.getComparison.getOp)) {
|
&& !(Op.EXISTS :: Op.NOT_EXISTS :: Nil).contains(it.getComparison.getOp) then
|
||||||
it.withParameterName(name.derive(null))
|
it.withParameterName(name.derive(null))
|
||||||
} else {
|
else
|
||||||
it
|
it
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a parameter by encoding a JSON object
|
* Create a parameter by encoding a JSON object
|
||||||
|
@ -25,10 +25,9 @@ class ConfigurationTest:
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("Dialect is derived from connection string")
|
@DisplayName("Dialect is derived from connection string")
|
||||||
def dialectIsDerived(): Unit =
|
def dialectIsDerived(): Unit =
|
||||||
try {
|
try
|
||||||
assertThrows(classOf[DocumentException], () => Configuration.dialect())
|
assertThrows(classOf[DocumentException], () => Configuration.dialect())
|
||||||
Configuration.setConnectionString("jdbc:postgresql:db")
|
Configuration.setConnectionString("jdbc:postgresql:db")
|
||||||
assertEquals(Dialect.POSTGRESQL, Configuration.dialect())
|
assertEquals(Dialect.POSTGRESQL, Configuration.dialect())
|
||||||
} finally {
|
finally
|
||||||
Configuration.setConnectionString(null)
|
Configuration.setConnectionString(null)
|
||||||
}
|
|
||||||
|
@ -22,13 +22,11 @@ class DialectTest:
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("deriveFromConnectionString fails when the connection string is unknown")
|
@DisplayName("deriveFromConnectionString fails when the connection string is unknown")
|
||||||
def deriveFailsWhenUnknown(): Unit =
|
def deriveFailsWhenUnknown(): Unit =
|
||||||
try {
|
try
|
||||||
Dialect.deriveFromConnectionString("SQL Server")
|
Dialect.deriveFromConnectionString("SQL Server")
|
||||||
fail("Dialect derivation should have failed")
|
fail("Dialect derivation should have failed")
|
||||||
} catch {
|
catch
|
||||||
case ex: DocumentException =>
|
case ex: DocumentException =>
|
||||||
assertNotNull(ex.getMessage, "The exception message should not have been null")
|
assertNotNull(ex.getMessage, "The exception message should not have been null")
|
||||||
assertTrue(ex.getMessage.contains("[SQL Server]"),
|
assertTrue(ex.getMessage.contains("[SQL Server]"),
|
||||||
"The connection string should have been in the exception message")
|
"The connection string should have been in the exception message")
|
||||||
}
|
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ class DocumentQueryTest:
|
|||||||
@Test
|
@Test
|
||||||
@DisplayName("insert generates auto random string | PostgreSQL")
|
@DisplayName("insert generates auto random string | PostgreSQL")
|
||||||
def insertAutoRandomPostgres(): Unit =
|
def insertAutoRandomPostgres(): Unit =
|
||||||
try {
|
try
|
||||||
ForceDialect.postgres()
|
ForceDialect.postgres()
|
||||||
Configuration.idStringLength = 8
|
Configuration.idStringLength = 8
|
||||||
val query = DocumentQuery.insert(TEST_TABLE, AutoId.RANDOM_STRING)
|
val query = DocumentQuery.insert(TEST_TABLE, AutoId.RANDOM_STRING)
|
||||||
@ -74,9 +74,8 @@ class DocumentQueryTest:
|
|||||||
assertEquals(8, query.replace(s"INSERT INTO $TEST_TABLE VALUES (:data::jsonb || '{\"id\":\"", "")
|
assertEquals(8, query.replace(s"INSERT INTO $TEST_TABLE VALUES (:data::jsonb || '{\"id\":\"", "")
|
||||||
.replace("\"}')", "").length,
|
.replace("\"}')", "").length,
|
||||||
"Random string length incorrect")
|
"Random string length incorrect")
|
||||||
} finally {
|
finally
|
||||||
Configuration.idStringLength = 16
|
Configuration.idStringLength = 16
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("insert generates auto random string | SQLite")
|
@DisplayName("insert generates auto random string | SQLite")
|
||||||
|
@ -23,7 +23,7 @@ object DocumentFunctions:
|
|||||||
"Inserting a document with a duplicate key should have thrown an exception")
|
"Inserting a document with a duplicate key should have thrown an exception")
|
||||||
|
|
||||||
def insertNumAutoId(db: ThrowawayDatabase): Unit =
|
def insertNumAutoId(db: ThrowawayDatabase): Unit =
|
||||||
try {
|
try
|
||||||
Configuration.autoIdStrategy = AutoId.NUMBER
|
Configuration.autoIdStrategy = AutoId.NUMBER
|
||||||
Configuration.idField = "key"
|
Configuration.idField = "key"
|
||||||
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
||||||
@ -36,13 +36,12 @@ object DocumentFunctions:
|
|||||||
val after = db.conn.findAll[NumIdDocument](TEST_TABLE, Field.named("key") :: Nil)
|
val after = db.conn.findAll[NumIdDocument](TEST_TABLE, Field.named("key") :: Nil)
|
||||||
assertEquals(4, after.size, "There should have been 4 documents returned")
|
assertEquals(4, after.size, "There should have been 4 documents returned")
|
||||||
assertEquals("1|2|77|78", after.fold("") { (acc, item) => s"$acc|$item" }, "The IDs were not generated correctly")
|
assertEquals("1|2|77|78", after.fold("") { (acc, item) => s"$acc|$item" }, "The IDs were not generated correctly")
|
||||||
} finally {
|
finally
|
||||||
Configuration.autoIdStrategy = AutoId.DISABLED
|
Configuration.autoIdStrategy = AutoId.DISABLED
|
||||||
Configuration.idField = "id"
|
Configuration.idField = "id"
|
||||||
}
|
|
||||||
|
|
||||||
def insertUUIDAutoId(db: ThrowawayDatabase): Unit =
|
def insertUUIDAutoId(db: ThrowawayDatabase): Unit =
|
||||||
try {
|
try
|
||||||
Configuration.autoIdStrategy = AutoId.UUID
|
Configuration.autoIdStrategy = AutoId.UUID
|
||||||
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
||||||
|
|
||||||
@ -51,12 +50,11 @@ object DocumentFunctions:
|
|||||||
val after = db.conn.findAll[JsonDocument](TEST_TABLE)
|
val after = db.conn.findAll[JsonDocument](TEST_TABLE)
|
||||||
assertEquals(1, after.size, "There should have been 1 document returned")
|
assertEquals(1, after.size, "There should have been 1 document returned")
|
||||||
assertEquals(32, after.head.id.length, "The ID was not generated correctly")
|
assertEquals(32, after.head.id.length, "The ID was not generated correctly")
|
||||||
} finally {
|
finally
|
||||||
Configuration.autoIdStrategy = AutoId.DISABLED
|
Configuration.autoIdStrategy = AutoId.DISABLED
|
||||||
}
|
|
||||||
|
|
||||||
def insertStringAutoId(db: ThrowawayDatabase): Unit =
|
def insertStringAutoId(db: ThrowawayDatabase): Unit =
|
||||||
try {
|
try
|
||||||
Configuration.autoIdStrategy = AutoId.RANDOM_STRING
|
Configuration.autoIdStrategy = AutoId.RANDOM_STRING
|
||||||
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
assertEquals(0L, db.conn.countAll(TEST_TABLE), "There should be no documents in the table")
|
||||||
|
|
||||||
@ -69,10 +67,9 @@ object DocumentFunctions:
|
|||||||
assertEquals(2, after.size, "There should have been 2 documents returned")
|
assertEquals(2, after.size, "There should have been 2 documents returned")
|
||||||
assertEquals(16, after.head.id.length, "The first document's ID was not generated correctly")
|
assertEquals(16, after.head.id.length, "The first document's ID was not generated correctly")
|
||||||
assertEquals(21, after(1).id.length, "The second document's ID was not generated correctly")
|
assertEquals(21, after(1).id.length, "The second document's ID was not generated correctly")
|
||||||
} finally {
|
finally
|
||||||
Configuration.autoIdStrategy = AutoId.DISABLED
|
Configuration.autoIdStrategy = AutoId.DISABLED
|
||||||
Configuration.idStringLength = 16
|
Configuration.idStringLength = 16
|
||||||
}
|
|
||||||
|
|
||||||
def saveMatch(db: ThrowawayDatabase): Unit =
|
def saveMatch(db: ThrowawayDatabase): Unit =
|
||||||
JsonDocument.load(db)
|
JsonDocument.load(db)
|
||||||
|
@ -47,13 +47,12 @@ object FindFunctions:
|
|||||||
|
|
||||||
def byIdNumber(db: ThrowawayDatabase): Unit =
|
def byIdNumber(db: ThrowawayDatabase): Unit =
|
||||||
Configuration.idField = "key"
|
Configuration.idField = "key"
|
||||||
try {
|
try
|
||||||
db.conn.insert(TEST_TABLE, NumIdDocument(18, "howdy"))
|
db.conn.insert(TEST_TABLE, NumIdDocument(18, "howdy"))
|
||||||
val doc = db.conn.findById[Int, NumIdDocument](TEST_TABLE, 18)
|
val doc = db.conn.findById[Int, NumIdDocument](TEST_TABLE, 18)
|
||||||
assertTrue(doc.isDefined, "The document should have been returned")
|
assertTrue(doc.isDefined, "The document should have been returned")
|
||||||
} finally {
|
finally
|
||||||
Configuration.idField = "id"
|
Configuration.idField = "id"
|
||||||
}
|
|
||||||
|
|
||||||
def byIdNotFound(db: ThrowawayDatabase): Unit =
|
def byIdNotFound(db: ThrowawayDatabase): Unit =
|
||||||
JsonDocument.load(db)
|
JsonDocument.load(db)
|
||||||
|
@ -71,13 +71,12 @@ object JsonFunctions:
|
|||||||
|
|
||||||
def byIdNumber (db: ThrowawayDatabase): Unit =
|
def byIdNumber (db: ThrowawayDatabase): Unit =
|
||||||
Configuration.idField = "key"
|
Configuration.idField = "key"
|
||||||
try {
|
try
|
||||||
db.conn.insert(TEST_TABLE, NumIdDocument(18, "howdy"))
|
db.conn.insert(TEST_TABLE, NumIdDocument(18, "howdy"))
|
||||||
assertEquals(maybeJsonB("""{"key":18,"text":"howdy"}"""), db.conn.jsonById(TEST_TABLE, 18),
|
assertEquals(maybeJsonB("""{"key":18,"text":"howdy"}"""), db.conn.jsonById(TEST_TABLE, 18),
|
||||||
"The document should have been found by numeric ID")
|
"The document should have been found by numeric ID")
|
||||||
} finally {
|
finally
|
||||||
Configuration.idField = "id"
|
Configuration.idField = "id"
|
||||||
}
|
|
||||||
|
|
||||||
def byIdNotFound (db: ThrowawayDatabase): Unit =
|
def byIdNotFound (db: ThrowawayDatabase): Unit =
|
||||||
JsonDocument.load(db)
|
JsonDocument.load(db)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user