From 932e9b2fb27f704a5b6b18bcd3836718c854aa81 Mon Sep 17 00:00:00 2001 From: liuyihai2002 Date: Fri, 12 Dec 2025 14:19:22 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E4=BF=AE=E6=94=B9op-engineering-op-sql?= =?UTF-8?q?ite=E5=BA=93=E7=9A=84=E4=B8=AD=E8=8B=B1=E6=96=87=E6=8C=87?= =?UTF-8?q?=E5=AF=BC=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: liuyihai2002 --- en/op-engineering-op-sqlite.md | 94 +++++++++++++++++++------------ zh-cn/op-engineering-op-sqlite.md | 3 +- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/en/op-engineering-op-sqlite.md b/en/op-engineering-op-sqlite.md index dcb9faee0..a02786348 100644 --- a/en/op-engineering-op-sqlite.md +++ b/en/op-engineering-op-sqlite.md @@ -68,30 +68,49 @@ import { import { open, - type DB + type DB, + Scalar, + HARMONY_DATABASE_PATH } from '@op-engineering/op-sqlite'; import { HARMONY_DATABASE_PATH } from '@react-native-ohos/op-sqlite'; export default function OpSqliteExample() { - + const [sqliteVersion, setSqliteVersion] = useState(''); + const handlePress = async () => { + try { + const db: DB = open({ + name: 'helloDb.sqlite', + encryptionKey: 'test', + location: HARMONY_DATABASE_PATH + }); + + const res = await db.execute('SELECT sqlite_version();'); + + // V8.0.3 + const version = res.rows?._array[0]['sqlite_version()']; + + // V14.0.1 + const version = res.rows[0]['sqlite_version()']; + + setSqliteVersion(version); + } catch (error) { + setSqliteVersion('Error getting version'); + } + }; + return ( { - let db:DB = open({ - name: 'helloDb.sqlite', - encryptionKey: 'test', - location: HARMONY_DATABASE_PATH - }); - }}> + onPress={handlePress} + > - tap to {'openDB'} + tap to {'openDB'} + {String(sqliteVersion)} - ); } @@ -314,13 +333,14 @@ Open the `YourProject/entry/src/main/module.json5` file and add the following co | Name | Description | Type | Required | Platform | HarmonyOS Support | | ---- | ----------- | ---- | -------- | -------- | ------------------ | -| getConstants | Return the corresponding database/file storage sandbox path. | () => {IOS_DOCUMENT_PATH,IOS_LIBRARY_PATH,ANDROID_DATABASE_PATH,ANDROID_FILES_PATH,ANDROID_EXTERNAL_FILES_PATH,HARMONY_DATABASE_PATH,HARMONY_FILES_PATH,} | no | all | yes | -| openSync | Synchronize the local database to the remote database and open the database. | (options: {url: string;authToken: string;name: string;location?: string;}) => DB; | no | all | yes | -| openRemote | Open the remote database. | (options: { url: string; authToken: string }) => DB; | no | all | yes | -| open | Open the database.encryptionKey indicates the key string required for using sqlcipher.After sqlcipher is enabled, encryptionKey is supported. | (options: {name: string;location?: string;encryptionKey?: string;}) => DB; | no | all | yes | -| isSQLCipher | Whether SQL cipher is enabled.(SQLCipher is an open source SQLite extension that provides transparent 256-bit AES full database encryption.) | () => boolean; | no | all | yes | -| isLibsql | Indicates whether to enable isLibsql. After isLibsql is enabled, the remote database and database synchronization interface can be enabled | () => boolean; | no | all | yes | -| moveAssetsDatabase | Copy the database to the specified path. | async (args: {filename: string;path?: string;overwrite?: boolean;}) => Promise | no | all | yes | +| `getConstants` | Return the corresponding database/file storage sandbox path. | () => {IOS_DOCUMENT_PATH,IOS_LIBRARY_PATH,ANDROID_DATABASE_PATH,ANDROID_FILES_PATH,ANDROID_EXTERNAL_FILES_PATH,HARMONY_DATABASE_PATH,HARMONY_FILES_PATH,} | no | all | yes | +| `openSync` | Synchronize the local database to the remote database and open the database. | (options: {url: string;authToken: string;name: string;location?: string;}) => DB; | no | all | yes | +| `openRemote` | Open the remote database. | (options: { url: string; authToken: string }) => DB; | no | all | yes | +| `open` | Open the database.encryptionKey indicates the key string required for using sqlcipher.After sqlcipher is enabled, encryptionKey is supported. | (options: {name: string;location?: string;encryptionKey?: string;}) => DB; | no | all | yes | +| `isSQLCipher` | Whether SQL cipher is enabled.(SQLCipher is an open source SQLite extension that provides transparent 256-bit AES full database encryption.) | () => boolean; | no | all | yes | +| `isLibsql` | Indicates whether to enable isLibsql. After isLibsql is enabled, the remote database and database synchronization interface can be enabled | () => boolean; | no | all | yes | +| `moveAssetsDatabase` | Copy the database to the specified path. | async (args: {filename: string;path?: string;overwrite?: boolean;}) => Promise | no | all | yes | +| `isIOSEmbeeded`14.0.1+ | Using the embedded version, you can never be sure which version is used | () => boolean; | no | all | yes | ### DB @@ -331,25 +351,25 @@ Open the `YourProject/entry/src/main/module.json5` file and add the following co | Name | Description | Type | Required | Platform | HarmonyOS Support | | ---- | ----------- | ---- | -------- | -------- | ------------------ | -| close | Shut down the database. | () => void; | no | all | yes | -| delete | Deleting a database | (location?: string) => void; | no | all | yes | -| attach | Attaching other databases to the primary database by aliasing | (mainDbName: string,dbNameToAttach: string,alias: string,location?: string) => void; | no | all | yes | -| detach | Detaching Other Databases from the Primary Database by Alias | (mainDbName: string, alias: string) => void; | no | all | yes | -| transaction | Operate through database transactions | (fn: (tx: Transaction) => Promise) => Promise; | no | all | yes | -| execute | Execute SQL statements in the database. | (query: string, params?: any[]) => QueryResult; | no | all | yes | -| executeWithHostObjects | The database query statement is used to quickly query a large amount of data. However, the return attribute access speed is slow. | (query: string,params?: any[]) => Promise; | no | all | yes | -| executeBatch | Query and execute a large number of statements. | (commands: SQLBatchTuple[]) => BatchQueryResult; | no | all | yes | -| loadFile | Load the local SQL file. | (location: string) => Promise; | no | all | yes | -| updateHook | Database update hook callback | (callback?:((params: \{table: string;operation: UpdateHookOperation;row?: any;rowId: number;}) => void) \| null) => void; | no | all | yes | -| commitHook | Database commit hook callback. | (callback?: (() => void) \| null) => void; | no | all | yes | -| rollbackHook | Database rollback hook callback. | (callback?: (() => void) \| null) => void; | no | all | yes | -| prepareStatement | You can reuse a query statement, use bind to change parameters, and execute the execution result. | (query: string) => PreparedStatementObj; | no | all | yes | -| loadExtension | Load SQL extension. | (path: string, entryPoint?: string) => void; | no | all | yes | -| executeRaw | If you do not care about the key, you can use this API to simplify the execution and return a component array.This should be much faster than the normal operation because you don't need to create objects with the same key. | (query: string,params?: any[]) => Promise; | no | all | yes | -| getDbPath | Obtaining the Database Path. | (location?: string) => string; | no | all | yes | -| reactiveExecute | Responsive statement query | (params: {query: string;arguments: any[];fireOn: {table: string;ids?: number[];}[];callback: (response: any) => void;}) => () => void; | no | all | yes | -| sync | Database synchronization operation, which is supported after isLibsql is enabled. | () => void | no | all | yes | - +| `close` | Shut down the database. | () => void; | no | all | yes | +| `delete` | Deleting a database | (location?: string) => void; | no | all | yes | +| `attach` | Attaching other databases to the primary database by aliasing | (mainDbName: string,dbNameToAttach: string,alias: string,location?: string) => void; | no | all | yes | +| `detach` | Detaching Other Databases from the Primary Database by Alias | (mainDbName: string, alias: string) => void; | no | all | yes | +| `transaction` | Operate through database transactions | (fn: (tx: Transaction) => Promise) => Promise; | no | all | yes | +| `execute` | Execute SQL statements in the database. | (query: string, params?: any[]) => QueryResult; | no | all | yes | +| `executeWithHostObjects` | The database query statement is used to quickly query a large amount of data. However, the return attribute access speed is slow. | (query: string,params?: any[]) => Promise; | no | all | yes | +| `executeBatch` | Query and execute a large number of statements. | (commands: SQLBatchTuple[]) => BatchQueryResult; | no | all | yes | +| `loadFile` | Load the local SQL file. | (location: string) => Promise; | no | all | yes | +| `updateHook` | Database update hook callback | (callback?:((params: \{table: string;operation: UpdateHookOperation;row?: any;rowId: number;}) => void) \| null) => void; | no | all | yes | +| `commitHook` | Database commit hook callback. | (callback?: (() => void) \| null) => void; | no | all | yes | +| `rollbackHook` | Database rollback hook callback. | (callback?: (() => void) \| null) => void; | no | all | yes | +| `prepareStatement` | You can reuse a query statement, use bind to change parameters, and execute the execution result. | (query: string) => PreparedStatementObj; | no | all | yes | +| `loadExtension` | Load SQL extension. | (path: string, entryPoint?: string) => void; | no | all | yes | +| `executeRaw` | If you do not care about the key, you can use this API to simplify the execution and return a component array.This should be much faster than the normal operation because you don't need to create objects with the same key. | (query: string,params?: any[]) => Promise; | no | all | yes | +| `getDbPath` | Obtaining the Database Path. | (location?: string) => string; | no | all | yes | +| `reactiveExecute` | Responsive statement query | (params: {query: string;arguments: any[];fireOn: {table: string;ids?: number[];}[];callback: (response: any) => void;}) => () => void; | no | all | yes | +| `sync` | Database synchronization operation, which is supported after isLibsql is enabled. | () => void | no | all | yes | +| `executeSync`14.0.1+ | Execute SQL statements in the database.Not available in transactions and must be used sparingly as it blocks the UI thread | (query: string, params?: Scalar[]) => QueryResult | no | all | yes | ## Known Issues diff --git a/zh-cn/op-engineering-op-sqlite.md b/zh-cn/op-engineering-op-sqlite.md index afc21ffc5..057c7ad39 100644 --- a/zh-cn/op-engineering-op-sqlite.md +++ b/zh-cn/op-engineering-op-sqlite.md @@ -82,7 +82,7 @@ export default function OpSqliteExample() { const res = await db.execute('SELECT sqlite_version();'); - // V8.0.2 + // V8.0.3 const version = res.rows?._array[0]['sqlite_version()']; // V14.0.1 @@ -372,7 +372,6 @@ ohpm install | `reactiveExecute` | Responsive statement query | (params: {query: string;arguments: any[];fireOn: {table: string;ids?: number[];}[];callback: (response: any) => void;}) => () => void; | no | all | yes | | `sync` | Database synchronization operation, which is supported after isLibsql is enabled. | () => void | no | all | yes | | `executeSync`14.0.1+ | Execute SQL statements in the database.Not available in transactions and must be used sparingly as it blocks the UI thread | (query: string, params?: Scalar[]) => QueryResult | no | all | yes | -| `flushPendingReactiveQueries`14.0.1+ | Flush pending reactive queries | () => Promise | no | all | yes | ## 遗留问题 -- Gitee