mirror of
https://github.com/haexhub/haex-hub.git
synced 2025-12-17 06:30:50 +01:00
refatored rust sql and drizzle
This commit is contained in:
@ -179,8 +179,9 @@ export const useWindowManagerStore = defineStore('windowManager', () => {
|
||||
|
||||
// Calculate viewport-aware size
|
||||
const viewportWidth = window.innerWidth
|
||||
const viewportHeight = window.innerHeight
|
||||
const viewportHeight = window.innerHeight - 60
|
||||
|
||||
console.log('viewportHeight', window.innerHeight, viewportHeight)
|
||||
const windowHeight = Math.min(height, viewportHeight)
|
||||
|
||||
// Adjust width proportionally if needed (optional)
|
||||
|
||||
@ -57,9 +57,11 @@ export const useUiStore = defineStore('uiStore', () => {
|
||||
colorMode.preference = currentThemeName.value
|
||||
})
|
||||
|
||||
const viewportHeightWithoutHeader = ref(0)
|
||||
|
||||
return {
|
||||
availableThemes,
|
||||
//currentScreenSize,
|
||||
viewportHeightWithoutHeader,
|
||||
currentTheme,
|
||||
currentThemeName,
|
||||
defaultTheme,
|
||||
|
||||
@ -136,43 +136,50 @@ const drizzleCallback = (async (
|
||||
params: unknown[],
|
||||
method: 'get' | 'run' | 'all' | 'values',
|
||||
) => {
|
||||
let rows: unknown[] = []
|
||||
let rows: any[] = []
|
||||
|
||||
try {
|
||||
if (isSelectQuery(sql)) {
|
||||
// SELECT statements
|
||||
rows = await invoke<unknown[]>('sql_select_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL select Error:', e, sql, params)
|
||||
return []
|
||||
})
|
||||
} else if (hasReturning(sql)) {
|
||||
// INSERT/UPDATE/DELETE with RETURNING → use query
|
||||
rows = await invoke<unknown[]>('sql_query_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL query with CRDT Error:', e, sql, params)
|
||||
return []
|
||||
})
|
||||
} else {
|
||||
// INSERT/UPDATE/DELETE without RETURNING → use execute
|
||||
await invoke<unknown[]>('sql_execute_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL execute with CRDT Error:', e, sql, params, rows)
|
||||
return []
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Fehler im drizzleCallback invoke:', error, {
|
||||
sql,
|
||||
params,
|
||||
method,
|
||||
})
|
||||
}
|
||||
|
||||
console.log('drizzleCallback', method, sql, params)
|
||||
console.log('drizzleCallback rows', rows)
|
||||
|
||||
if (isSelectQuery(sql)) {
|
||||
// SELECT statements
|
||||
rows = await invoke<unknown[]>('sql_select_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL select Error:', e, sql, params)
|
||||
return []
|
||||
})
|
||||
} else if (hasReturning(sql)) {
|
||||
// INSERT/UPDATE/DELETE with RETURNING → use query
|
||||
rows = await invoke<unknown[]>('sql_query_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL query with CRDT Error:', e, sql, params)
|
||||
return []
|
||||
})
|
||||
} else {
|
||||
// INSERT/UPDATE/DELETE without RETURNING → use execute
|
||||
await invoke<unknown[]>('sql_execute_with_crdt', {
|
||||
sql,
|
||||
params,
|
||||
}).catch((e) => {
|
||||
console.error('SQL execute with CRDT Error:', e, sql, params, rows)
|
||||
return []
|
||||
})
|
||||
}
|
||||
|
||||
console.log('drizzle found', rows)
|
||||
if (method === 'get') {
|
||||
return { rows: rows.length > 0 ? [rows[0]] : [] }
|
||||
} else {
|
||||
return { rows }
|
||||
return rows.length > 0 ? { rows: rows[0] } : { rows }
|
||||
}
|
||||
return { rows }
|
||||
}) satisfies AsyncRemoteCallback
|
||||
|
||||
@ -1,89 +1,30 @@
|
||||
import { invoke } from '@tauri-apps/api/core'
|
||||
import { load } from '@tauri-apps/plugin-store'
|
||||
|
||||
/* interface ILastVault {
|
||||
lastUsed: Date
|
||||
name: string
|
||||
path: string
|
||||
} */
|
||||
|
||||
export interface IVaultInfo {
|
||||
name: string
|
||||
path: string
|
||||
lastAccess: Date
|
||||
}
|
||||
import type { VaultInfo } from '@bindings/VaultInfo'
|
||||
|
||||
export const useLastVaultStore = defineStore('lastVaultStore', () => {
|
||||
const {
|
||||
public: { haexVault },
|
||||
} = useRuntimeConfig()
|
||||
|
||||
const lastVaults = ref<IVaultInfo[]>([])
|
||||
|
||||
const keyName = 'lastVaults'
|
||||
|
||||
const getStoreAsync = async () => {
|
||||
return await load(haexVault.lastVaultFileName || 'lastVaults.json')
|
||||
}
|
||||
const lastVaults = ref<VaultInfo[]>([])
|
||||
|
||||
const syncLastVaultsAsync = async () => {
|
||||
lastVaults.value =
|
||||
(await listVaultsAsync()).sort(
|
||||
(a, b) => +new Date(b.lastAccess) - +new Date(a.lastAccess),
|
||||
(a, b) => +new Date(`${b.lastAccess}`) - +new Date(`${a.lastAccess}`),
|
||||
) ?? []
|
||||
|
||||
return lastVaults.value
|
||||
}
|
||||
|
||||
const listVaultsAsync = async () => {
|
||||
lastVaults.value = await invoke<IVaultInfo[]>('list_vaults')
|
||||
lastVaults.value = await invoke<VaultInfo[]>('list_vaults')
|
||||
return lastVaults.value
|
||||
}
|
||||
|
||||
const addVaultAsync = async ({
|
||||
name,
|
||||
path,
|
||||
}: {
|
||||
name?: string
|
||||
path: string
|
||||
}) => {
|
||||
if (!lastVaults.value) await syncLastVaultsAsync()
|
||||
|
||||
const saveName = name || getFileNameFromPath(path)
|
||||
lastVaults.value = lastVaults.value.filter((vault) => vault.path !== path)
|
||||
lastVaults.value.push({ lastAccess: new Date(), name: saveName, path })
|
||||
await saveLastVaultsAsync()
|
||||
}
|
||||
|
||||
const removeVaultAsync = async (vaultPath: string) => {
|
||||
lastVaults.value = lastVaults.value.filter(
|
||||
(vault) => vault.path !== vaultPath,
|
||||
)
|
||||
await saveLastVaultsAsync()
|
||||
}
|
||||
|
||||
const saveLastVaultsAsync = async () => {
|
||||
const store = await getStoreAsync()
|
||||
await store.set(keyName, lastVaults.value)
|
||||
await syncLastVaultsAsync()
|
||||
const removeVaultAsync = async (vaultName: string) => {
|
||||
return await invoke('delete_vault', { vaultName })
|
||||
}
|
||||
|
||||
return {
|
||||
addVaultAsync,
|
||||
syncLastVaultsAsync,
|
||||
lastVaults,
|
||||
removeVaultAsync,
|
||||
saveLastVaultsAsync,
|
||||
}
|
||||
})
|
||||
|
||||
const getFileNameFromPath = (path: string) => {
|
||||
const lastBackslashIndex = path.lastIndexOf('\\')
|
||||
const lastSlashIndex = path.lastIndexOf('/')
|
||||
|
||||
const lastIndex = Math.max(lastBackslashIndex, lastSlashIndex)
|
||||
|
||||
const fileName = path.substring(lastIndex + 1)
|
||||
|
||||
return fileName
|
||||
}
|
||||
|
||||
@ -32,6 +32,7 @@ export const useVaultSettingsStore = defineStore('vaultSettingsStore', () => {
|
||||
where: eq(schema.haexSettings.key, VaultSettingsKeyEnum.locale),
|
||||
})
|
||||
|
||||
console.log('found currentLocaleRow', currentLocaleRow)
|
||||
if (currentLocaleRow?.value) {
|
||||
const currentLocale = app.$i18n.availableLocales.find(
|
||||
(locale) => locale === currentLocaleRow.value,
|
||||
@ -70,6 +71,7 @@ export const useVaultSettingsStore = defineStore('vaultSettingsStore', () => {
|
||||
where: eq(schema.haexSettings.key, VaultSettingsKeyEnum.theme),
|
||||
})
|
||||
|
||||
console.log('found currentThemeRow', currentThemeRow)
|
||||
if (currentThemeRow?.value) {
|
||||
const theme = availableThemes.value.find(
|
||||
(theme) => theme.value === currentThemeRow.value,
|
||||
@ -98,6 +100,7 @@ export const useVaultSettingsStore = defineStore('vaultSettingsStore', () => {
|
||||
where: eq(schema.haexSettings.key, VaultSettingsKeyEnum.vaultName),
|
||||
})
|
||||
|
||||
console.log('found currentVaultNameRow', currentVaultNameRow)
|
||||
if (currentVaultNameRow?.value) {
|
||||
currentVaultName.value =
|
||||
currentVaultNameRow.value || haexVault.defaultVaultName || 'HaexHub'
|
||||
@ -129,7 +132,7 @@ export const useVaultSettingsStore = defineStore('vaultSettingsStore', () => {
|
||||
),
|
||||
})
|
||||
console.log('store: readDeviceNameAsync', deviceName)
|
||||
return deviceName
|
||||
return deviceName?.id ? deviceName : undefined
|
||||
}
|
||||
|
||||
const addDeviceNameAsync = async ({
|
||||
|
||||
Reference in New Issue
Block a user