mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 15:08:06 +08:00
refactor: extract sqlite types
This commit is contained in:
31
web/app/components/workflow/skill/hooks/sqlite/types.ts
Normal file
31
web/app/components/workflow/skill/hooks/sqlite/types.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import type { MemoryVFS } from 'wa-sqlite/src/examples/MemoryVFS.js'
|
||||
|
||||
type SQLiteModuleType = typeof import('wa-sqlite')
|
||||
|
||||
export type SQLiteValue = string | number | bigint | Uint8Array | null
|
||||
|
||||
export type SQLiteQueryResult = {
|
||||
columns: string[]
|
||||
values: SQLiteValue[][]
|
||||
}
|
||||
|
||||
export type SQLiteAPI = ReturnType<SQLiteModuleType['Factory']>
|
||||
export type SQLiteVFS = Parameters<SQLiteAPI['vfs_register']>[0]
|
||||
|
||||
export type SQLiteClient = {
|
||||
sqlite3: SQLiteAPI
|
||||
sqlite: SQLiteModuleType
|
||||
vfs: MemoryVFS
|
||||
}
|
||||
|
||||
export type SQLiteState = {
|
||||
tables: string[]
|
||||
isLoading: boolean
|
||||
error: Error | null
|
||||
}
|
||||
|
||||
export type SQLiteAction
|
||||
= | { type: 'reset' }
|
||||
| { type: 'loading' }
|
||||
| { type: 'success', tables: string[] }
|
||||
| { type: 'error', error: Error }
|
||||
@ -1,12 +1,14 @@
|
||||
import type { MemoryVFS } from 'wa-sqlite/src/examples/MemoryVFS.js'
|
||||
import type {
|
||||
SQLiteAction,
|
||||
SQLiteClient,
|
||||
SQLiteQueryResult,
|
||||
SQLiteState,
|
||||
SQLiteValue,
|
||||
SQLiteVFS,
|
||||
} from './sqlite/types'
|
||||
import { useCallback, useEffect, useReducer, useRef } from 'react'
|
||||
|
||||
export type SQLiteValue = string | number | bigint | Uint8Array | null
|
||||
|
||||
export type SQLiteQueryResult = {
|
||||
columns: string[]
|
||||
values: SQLiteValue[][]
|
||||
}
|
||||
export type { SQLiteQueryResult, SQLiteValue } from './sqlite/types'
|
||||
|
||||
export type UseSQLiteDatabaseResult = {
|
||||
tables: string[]
|
||||
@ -15,28 +17,6 @@ export type UseSQLiteDatabaseResult = {
|
||||
queryTable: (tableName: string, limit?: number) => Promise<SQLiteQueryResult | null>
|
||||
}
|
||||
|
||||
type SQLiteModuleType = typeof import('wa-sqlite')
|
||||
type SQLiteAPI = ReturnType<SQLiteModuleType['Factory']>
|
||||
type SQLiteVFS = Parameters<SQLiteAPI['vfs_register']>[0]
|
||||
|
||||
type SQLiteClient = {
|
||||
sqlite3: ReturnType<SQLiteModuleType['Factory']>
|
||||
sqlite: SQLiteModuleType
|
||||
vfs: MemoryVFS
|
||||
}
|
||||
|
||||
type SQLiteState = {
|
||||
tables: string[]
|
||||
isLoading: boolean
|
||||
error: Error | null
|
||||
}
|
||||
|
||||
type SQLiteAction
|
||||
= | { type: 'reset' }
|
||||
| { type: 'loading' }
|
||||
| { type: 'success', tables: string[] }
|
||||
| { type: 'error', error: Error }
|
||||
|
||||
const TABLES_QUERY = 'SELECT name FROM sqlite_master WHERE type=\'table\' AND name NOT LIKE \'sqlite_%\' ORDER BY name'
|
||||
|
||||
let sqliteClientPromise: Promise<SQLiteClient> | null = null
|
||||
|
||||
Reference in New Issue
Block a user