Skip to content

Commit f928707

Browse files
committed
feat(desktop): export sqlite database
1 parent 03cfbbc commit f928707

File tree

12 files changed

+37
-40
lines changed

12 files changed

+37
-40
lines changed

apps/desktop/layer/renderer/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@dnd-kit/core": "6.3.1",
1616
"@dnd-kit/sortable": "10.0.0",
1717
"@electron-toolkit/preload": "3.0.2",
18+
"@follow/database": "workspace:*",
1819
"@follow/electron-main": "workspace:*",
1920
"@follow/shared": "workspace:*",
2021
"@follow/store": "workspace:*",
@@ -48,7 +49,6 @@
4849
"cmdk": "1.1.1",
4950
"dayjs": "1.11.13",
5051
"dexie": "4.0.11",
51-
"dexie-export-import": "4.1.4",
5252
"dnum": "2.15.0",
5353
"embla-carousel-react": "8.6.0",
5454
"embla-carousel-wheel-gestures": "8.0.2",

apps/desktop/layer/renderer/src/database/db.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,6 @@ class BrowserDB extends Dexie {
7979

8080
export const browserDB = new BrowserDB()
8181

82-
export const exportDB = async () => {
83-
await import("dexie-export-import")
84-
const blob = await browserDB.export({ prettyJson: true })
85-
const url = URL.createObjectURL(blob)
86-
const a = document.createElement("a")
87-
a.href = url
88-
a.download = `${LOCAL_DB_NAME}.json`
89-
a.click()
90-
}
91-
9282
// ================================================ //
9383
// ================================================ //
9484
// ================================================ //

apps/desktop/layer/renderer/src/modules/settings/tabs/data-control.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { Input } from "@follow/components/ui/input/Input.js"
1313
import { Label } from "@follow/components/ui/label/index.jsx"
1414
import { RadioGroup, RadioGroupItem } from "@follow/components/ui/radio-group/motion.js"
1515
import { Slider } from "@follow/components/ui/slider/index.js"
16+
import { exportDB } from "@follow/database/db"
1617
import { ELECTRON_BUILD } from "@follow/shared/constants"
1718
import { env } from "@follow/shared/env.desktop"
1819
import { zodResolver } from "@hookform/resolvers/zod"
@@ -24,7 +25,6 @@ import { z } from "zod"
2425

2526
import { setGeneralSetting, useGeneralSettingValue } from "~/atoms/settings/general"
2627
import { useDialog, useModalStack } from "~/components/ui/modal/stacked/hooks"
27-
import { exportDB } from "~/database"
2828
import { ipcServices } from "~/lib/client"
2929
import { queryClient } from "~/lib/query-client"
3030
import { clearLocalPersistStoreData } from "~/store/utils/clear"

apps/mobile/src/initialize/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { initializeDb } from "@follow/database/db"
1+
import { initializeDB } from "@follow/database/db"
22
import { hydrateDatabaseToStore } from "@follow/store/hydrate"
33
import { tracker } from "@follow/tracker"
44
import { nativeApplicationVersion } from "expo-application"
@@ -21,7 +21,7 @@ export const initializeApp = async () => {
2121
const now = Date.now()
2222

2323
await initDeviceType()
24-
initializeDb()
24+
initializeDB()
2525

2626
await apm("migrateDatabase", migrateDatabase)
2727
initializeDayjs()

apps/mobile/src/initialize/migration.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { migrateDb } from "@follow/database/db"
1+
import { migrateDB } from "@follow/database/db"
22
import { useSyncExternalStore } from "react"
33

44
let storeChangeFn: () => void
@@ -16,7 +16,7 @@ const migrateStore = {
1616

1717
export const migrateDatabase = async () => {
1818
try {
19-
await migrateDb()
19+
await migrateDB()
2020
migrateStore.success = true
2121
storeChangeFn?.()
2222
} catch (error) {

locales/settings/en.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
"general.export_data.title": "Export Data",
215215
"general.export_database.button": "Export",
216216
"general.export_database.description": "Export all your data, including articles (Full Backup).",
217-
"general.export_database.label": "Export Database (JSON)",
217+
"general.export_database.label": "Export Database",
218218
"general.group_by_date.description": "Group entries by date.",
219219
"general.group_by_date.label": "Group by date",
220220
"general.hide_all_read_subscriptions.description": "Hide subscriptions without unread entries in the subscription list.",

locales/settings/zh-CN.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
"general.export_data.title": "导出数据",
207207
"general.export_database.button": "导出",
208208
"general.export_database.description": "导出你的所有数据,包括文章(完整备份)。",
209-
"general.export_database.label": "导出数据库 (JSON)",
209+
"general.export_database.label": "导出数据库",
210210
"general.group_by_date.description": "按日期对条目进行分组。",
211211
"general.group_by_date.label": "按日期分组",
212212
"general.hide_all_read_subscriptions.description": "在订阅列表中隐藏没有未读条目的订阅。",

packages/internal/database/src/db.desktop.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@ export const sqlite = new SQLocalDrizzle(dbName)
2121

2222
let db: SqliteRemoteDatabase<typeof schema>
2323

24-
export function initializeDb() {
24+
export function initializeDB() {
2525
db = drizzle(sqlite.driver, sqlite.batchDriver, {
2626
schema,
2727
logger: false,
2828
})
2929
}
3030
export { db }
3131

32-
export async function migrateDb() {
32+
export async function migrateDB() {
3333
try {
3434
await migrate(db, migrations)
3535
} catch (error) {
@@ -39,3 +39,16 @@ export async function migrateDb() {
3939
await migrate(db, migrations)
4040
}
4141
}
42+
43+
export async function exportDB() {
44+
const databaseFile = await sqlite.getDatabaseFile()
45+
const fileUrl = URL.createObjectURL(databaseFile)
46+
47+
const a = document.createElement("a")
48+
a.href = fileUrl
49+
a.download = "database.sqlite3"
50+
a.click()
51+
a.remove()
52+
53+
URL.revokeObjectURL(fileUrl)
54+
}

packages/internal/database/src/db.rn.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ let db: ExpoSQLiteDatabase<typeof schema> & {
1313
$client: SQLite.SQLiteDatabase
1414
}
1515

16-
export function initializeDb() {
16+
export function initializeDB() {
1717
db = drizzle(sqlite, {
1818
schema,
1919
logger: false,
2020
})
2121
}
2222
export { db }
2323

24-
export async function migrateDb(): Promise<void> {
24+
export async function migrateDB(): Promise<void> {
2525
try {
2626
await migrate(db, migrations)
2727
} catch (error) {
@@ -33,7 +33,9 @@ export async function migrateDb(): Promise<void> {
3333
}
3434
await SQLite.deleteDatabaseAsync(SQLITE_DB_NAME)
3535
sqlite = SQLite.openDatabaseSync(SQLITE_DB_NAME)
36-
initializeDb()
36+
initializeDB()
3737
await migrate(db, migrations)
3838
}
3939
}
40+
41+
export async function exportDB() {}

packages/internal/database/src/db.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import type { DB } from "./types"
22

33
export declare const sqlite: unknown
44
export declare const db: DB
5-
export declare function initializeDb(): void
6-
export declare function migrateDb(): Promise<void>
5+
export declare function initializeDB(): void
6+
export declare function migrateDB(): Promise<void>
7+
export declare function exportDB(): Promise<Blob>

0 commit comments

Comments
 (0)