mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 06:30:50 +01:00
generate table structs from ts in rust
This commit is contained in:
@ -1,20 +1,32 @@
|
||||
import { integer, sqliteTable, text } from 'drizzle-orm/sqlite-core'
|
||||
import { integer, sqliteTable, text, index } from 'drizzle-orm/sqlite-core'
|
||||
import tableNames from '../tableNames.json'
|
||||
|
||||
export const haexCrdtLogs = sqliteTable(tableNames.haex.crdt.logs, {
|
||||
hlc_timestamp: text().primaryKey(),
|
||||
table_name: text(),
|
||||
row_pks: text({ mode: 'json' }),
|
||||
op_type: text({ enum: ['INSERT', 'UPDATE', 'DELETE'] }),
|
||||
column_name: text(),
|
||||
new_value: text({ mode: 'json' }),
|
||||
old_value: text({ mode: 'json' }),
|
||||
})
|
||||
export const haexCrdtLogs = sqliteTable(
|
||||
tableNames.haex.crdt.logs,
|
||||
{
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
haexTimestamp: text('haex_timestamp'),
|
||||
tableName: text('table_name'),
|
||||
rowPks: text('row_pks', { mode: 'json' }),
|
||||
opType: text('op_type', { enum: ['INSERT', 'UPDATE', 'DELETE'] }),
|
||||
columnName: text('column_name'),
|
||||
newValue: text('new_value', { mode: 'json' }),
|
||||
oldValue: text('old_value', { mode: 'json' }),
|
||||
},
|
||||
(table) => [
|
||||
index('idx_haex_timestamp').on(table.haexTimestamp),
|
||||
index('idx_table_row').on(table.tableName, table.rowPks),
|
||||
],
|
||||
)
|
||||
export type InsertHaexCrdtLogs = typeof haexCrdtLogs.$inferInsert
|
||||
export type SelectHaexCrdtLogs = typeof haexCrdtLogs.$inferSelect
|
||||
|
||||
export const haexCrdtSnapshots = sqliteTable(tableNames.haex.crdt.snapshots, {
|
||||
snapshot_id: text().primaryKey(),
|
||||
snapshot_id: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
created: text(),
|
||||
epoch_hlc: text(),
|
||||
location_url: text(),
|
||||
@ -22,6 +34,8 @@ export const haexCrdtSnapshots = sqliteTable(tableNames.haex.crdt.snapshots, {
|
||||
})
|
||||
|
||||
export const haexCrdtConfigs = sqliteTable(tableNames.haex.crdt.configs, {
|
||||
key: text().primaryKey(),
|
||||
key: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
value: text(),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user