Skip to content

Commit

Permalink
Added defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
Brage committed Jul 10, 2023
1 parent 9692954 commit 5126312
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 11 deletions.
13 changes: 13 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

70 changes: 62 additions & 8 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package no.iktdev.streamit.library.db.tables

import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.javatime.timestamp
import org.jetbrains.exposed.sql.transactions.transaction
import java.time.Instant

object catalog : IntIdTable() {
Expand All @@ -12,7 +14,7 @@ object catalog : IntIdTable() {
var collection: Column<String> = varchar("collection", 100)
var iid: Column<Int?> = integer("iid").nullable()
var genres: Column<String?> = varchar("genres", 24).nullable()
val added: Column<Instant> = timestamp("added")
val added: Column<Instant> = timestamp("added").default(Instant.now())

init {
uniqueIndex(title, type)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package no.iktdev.streamit.library.db.tables

import no.iktdev.streamit.library.db.tables.catalog.default
import org.jetbrains.exposed.dao.id.IntIdTable
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.javatime.timestamp
import java.time.Instant

object progress : IntIdTable() {
val guid: Column<String> = varchar("guid", 50)
Expand All @@ -13,5 +16,5 @@ object progress : IntIdTable() {
val video: Column<String> = varchar("video", 100)
val progress: Column<Int> = integer("progress")
val duration: Column<Int> = integer("duration")
val played: Column<Int?> = integer("played").nullable()
val played: Column<Instant?> = timestamp("played").default(Instant.now()).nullable()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package no.iktdev.streamit.library.db.tables

import org.jetbrains.exposed.dao.id.EntityID
import org.jetbrains.exposed.sql.Column
import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.statements.InsertStatement
import org.jetbrains.exposed.sql.update

import org.jetbrains.exposed.sql.transactions.transaction

open class TableDefaultOperations<T: Table> {

fun <T> Table.insertWithSuccess(block: () -> T): Boolean {
return try {
transaction { block }
true
} catch (e : Exception) {
e.printStackTrace()
false
}
}


protected fun <T> withTransaction(block: () -> T): T? {
return try {
transaction { block() }
} catch (e: Exception) {
// log the error here
null
}
}
}

0 comments on commit 5126312

Please sign in to comment.