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(),
|
||||
})
|
||||
|
||||
@ -9,18 +9,22 @@ import {
|
||||
import tableNames from '../tableNames.json'
|
||||
|
||||
export const haexSettings = sqliteTable(tableNames.haex.settings, {
|
||||
id: text().primaryKey(),
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
key: text(),
|
||||
type: text(),
|
||||
value: text(),
|
||||
haex_tombstone: integer({ mode: 'boolean' }),
|
||||
haex_timestamp: text(),
|
||||
haexTombstone: integer('haex_tombstone', { mode: 'boolean' }),
|
||||
haexTimestamp: text('haex_timestamp'),
|
||||
})
|
||||
export type InsertHaexSettings = typeof haexSettings.$inferInsert
|
||||
export type SelectHaexSettings = typeof haexSettings.$inferSelect
|
||||
|
||||
export const haexExtensions = sqliteTable(tableNames.haex.extensions, {
|
||||
id: text().primaryKey(),
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
author: text(),
|
||||
description: text(),
|
||||
entry: text(),
|
||||
@ -32,8 +36,8 @@ export const haexExtensions = sqliteTable(tableNames.haex.extensions, {
|
||||
signature: text(),
|
||||
url: text(),
|
||||
version: text(),
|
||||
haex_tombstone: integer({ mode: 'boolean' }),
|
||||
haex_timestamp: text(),
|
||||
haexTombstone: integer('haex_tombstone', { mode: 'boolean' }),
|
||||
haexTimestamp: text('haex_timestamp'),
|
||||
})
|
||||
export type InsertHaexExtensions = typeof haexExtensions.$inferInsert
|
||||
export type SelectHaexExtensions = typeof haexExtensions.$inferSelect
|
||||
@ -41,7 +45,9 @@ export type SelectHaexExtensions = typeof haexExtensions.$inferSelect
|
||||
export const haexExtensionPermissions = sqliteTable(
|
||||
tableNames.haex.extension_permissions,
|
||||
{
|
||||
id: text().primaryKey(),
|
||||
id: text()
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
extensionId: text('extension_id').references(
|
||||
(): AnySQLiteColumn => haexExtensions.id,
|
||||
),
|
||||
|
||||
2
src-tauri/database/schemas/index.ts
Normal file
2
src-tauri/database/schemas/index.ts
Normal file
@ -0,0 +1,2 @@
|
||||
export * from './crdt'
|
||||
export * from './haex'
|
||||
Reference in New Issue
Block a user