ㅎㅎㅎ
This commit is contained in:
@@ -8,6 +8,7 @@ import org.jetbrains.exposed.sql.transactions.transaction
|
||||
import java.io.File
|
||||
import java.time.LocalDateTime
|
||||
|
||||
|
||||
object TradeStatus {
|
||||
const val PENDING_BUY = "PENDING_BUY" // 매수 주문 중
|
||||
const val MONITORING = "MONITORING" // 매수 체결 후 감시 중
|
||||
@@ -62,41 +63,6 @@ object TradeLogTable : Table("trade_logs") {
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
class VectorColumnType(private val dimension: Int) : ColumnType<DoubleArray>() {
|
||||
override fun sqlType(): String = "FLOAT8 ARRAY"
|
||||
|
||||
override fun valueFromDB(value: Any): DoubleArray {
|
||||
return when (value) {
|
||||
// H2 드라이버에서 반환된 객체를 처리
|
||||
is java.sql.Array -> {
|
||||
val array = value.array as Array<*>
|
||||
array.map { (it as Number).toDouble() }.toDoubleArray()
|
||||
}
|
||||
is Array<*> -> value.map { (it as Number).toDouble() }.toDoubleArray()
|
||||
is DoubleArray -> value
|
||||
else -> DoubleArray(0)
|
||||
}
|
||||
}
|
||||
|
||||
// [핵심 수정 부분]
|
||||
// primitive double[]을 Object Double[]로 변환하여 반환합니다.
|
||||
// 이렇게 해야 H2 JDBC 드라이버가 직렬화 대신 SQL ARRAY로 인식합니다.
|
||||
override fun notNullValueToDB(value: DoubleArray): Any {
|
||||
return value.toTypedArray()
|
||||
}
|
||||
}
|
||||
|
||||
object VectorStoreTable : Table("VECTOR_STORE") {
|
||||
val id = integer("id").autoIncrement()
|
||||
val content = text("content")
|
||||
val metadata = text("metadata")
|
||||
|
||||
// 이제 이 컬럼은 DoubleArray 데이터를 직접 주고받습니다.
|
||||
val embedding = registerColumn<DoubleArray>("embedding", VectorColumnType(1024))
|
||||
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
object DatabaseFactory {
|
||||
fun init() {
|
||||
val dbPath = File("db/autotrade_db").absolutePath
|
||||
@@ -106,16 +72,13 @@ object DatabaseFactory {
|
||||
)
|
||||
|
||||
transaction {
|
||||
|
||||
// 테이블 생성 (AutoTradeTable 포함)
|
||||
SchemaUtils.createMissingTablesAndColumns(ConfigTable, TradeLogTable, AutoTradeTable,VectorStoreTable)
|
||||
SchemaUtils.createMissingTablesAndColumns(ConfigTable, TradeLogTable, AutoTradeTable)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --- 자동매매(감시) 관련 함수 ---
|
||||
|
||||
|
||||
/**
|
||||
* 새로운 자동매매 건 등록 (주로 PENDING_BUY 상태로 시작)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user