Skip to content

重构桥接方法&事件执行&多SQL循环执行 #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ xcuserdata
android/.gradle/
# node.js
#
index.lock
node_modules/
npm-debug.log
*.iml
Expand Down
20 changes: 13 additions & 7 deletions NativeSQLitePlugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,19 @@ import type {TurboModule } from 'react-native/Libraries/TurboModule/RCTExport';
import {TurboModuleRegistry} from 'react-native';

export interface Spec extends TurboModule {
DEBUG(isDebug: boolean): void;
enablePromise(enablePromise: boolean): void;
openDatabase(dbname:string,dbVersion:string,dbDisplayname:string,dbSize:number,success?: () => void,error?: (e: Object) => void,): Object;
deleteDatabase(dbname: string, success?: () => void, error?: (err: Object) => void): void;
executeSql(store:Object,statement: string, params?: any[], success?: (s?: Object) => void, error?: (e: Object) => void): Promise<void>;
// transaction(scope: (tx: Transaction) => void,error?: (e: Object) => void,success?: () => void,): void;
close(store:Object,success: () => void, error: (err: Object) => void): void;

open(openargs:Object,opensuccesscb:() => void,openerrorcb:(e:Object) => void):void;

close(closeargs:Object,mysuccess:(t:Object,r:Object) => void,myerror:(e:Object) => void):void;

attach(attachargs:Object,mysuccess:(t:Object,r:Object) => void,myerror:(e:Object) => void):void;

backgroundExecuteSqlBatch(args:Object,mysuccess:(result:Object) => void,myerror:(e:Object) => void):void;

echoStringValue(openargs:Object,mysuccess:(testValue:Object) => void,myerror:(e:Object) => void):void;

delete(args:Object,mysuccess:(r:Object) => void,myerror:(e:Object) => void):void;

}

export default TurboModuleRegistry.getEnforcing<Spec>('SQLitePlugin');
3 changes: 0 additions & 3 deletions SQLitePlugin.ts

This file was deleted.

18 changes: 16 additions & 2 deletions lib/sqlite.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
* See http://opensource.org/licenses/alphabetical for full text.
*/

var NativeModules = require("react-native").NativeModules;
// var NativeModules = require("react-native").NativeModules;
import NativeModules from '../NativeSQLitePlugin'
var DB_STATE_INIT, DB_STATE_OPEN, READ_ONLY_REGEX, SQLiteFactory, SQLitePlugin, SQLitePluginTransaction, argsArray, dblocations, newSQLError, txLocks;

var plugin = {};
Expand Down Expand Up @@ -86,7 +87,20 @@ plugin.exec = function(method, options, success, error) {
if (plugin.sqlitePlugin.DEBUG){
plugin.log("SQLite." + method + "(" + JSON.stringify(options) + ")");
}
NativeModules["SQLite"][method](options,success,error);
// NativeModules["SQLite"][method](options,success,error);
if(method=='open'){
NativeModules.open(options,success,error);
}else if(method=='close'){
NativeModules.close(options,success,error);
}else if(method=='attach'){
NativeModules.attach(options,success,error);
}else if(method=='backgroundExecuteSqlBatch'){
NativeModules.backgroundExecuteSqlBatch(options,success,error);
}else if(method=='echoStringValue'){
NativeModules.echoStringValue(options,success,error);
}else if(method=='delete'){
NativeModules.delete(options,success,error);
}
};

plugin.log = function(...messages) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-native-oh-tpl/react-native-sqlite-storage",
"version": "6.0.1-0.0.1",
"version": "6.0.1-0.0.16",
"description": "SQLite3 bindings for React Native (Android & iOS)",
"overrides":{
"@react-native/codegen": "0.74.0"
Expand Down
Binary file modified platforms/harmony/sqlite_storage.har
Binary file not shown.
22 changes: 11 additions & 11 deletions platforms/harmony/sqlite_storage/src/main/ets/CommonConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@
import relationalStore from '@ohos.data.relationalStore';

export default class CommonConstants {
/**
* Rdb database config.
*/
static readonly STORE_CONFIG: relationalStore.StoreConfig = {
name: 'RKSQLite.db',
securityLevel: relationalStore.SecurityLevel.S1
};
/**
* Log tag.
*/
static readonly TAG = '[RNOH] SQLiteStorage';
/**
* Rdb database config.
*/
static readonly STORE_CONFIG: relationalStore.StoreConfig = {
name: 'RKSQLite.db',
securityLevel: relationalStore.SecurityLevel.S1
};
/**
* Log tag.
*/
static readonly TAG = '[RNOH] SQLiteStorage';
}
22 changes: 11 additions & 11 deletions platforms/harmony/sqlite_storage/src/main/ets/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,34 +30,34 @@ class Logger {
private format: string = '%{public}s, %{public}s';
private isDebug: boolean = true;

/**
/**
* constructor.
*
*
* @param Prefix Identifies the log tag.
* @param domain Domain Indicates the service domain, which is a hexadecimal integer ranging from 0x0 to 0xFFFFF.
*/
constructor(prefix: string = 'MyApp', domain: number = 0xFF00, isDebug = true) {
this.prefix = prefix;
this.domain = domain;
this.isDebug = isDebug;
this.prefix = prefix;
this.domain = domain;
this.isDebug = isDebug;
}

debug(...args: string[]): void {
if(this.isDebug) {
hilog.debug(this.domain, this.prefix, this.format, args);
}
if (this.isDebug) {
hilog.debug(this.domain, this.prefix, this.format, args);
}
}

info(...args: string[]): void {
hilog.info(this.domain, this.prefix, this.format, args);
hilog.info(this.domain, this.prefix, this.format, args);
}

warn(...args: string[]): void {
hilog.warn(this.domain, this.prefix, this.format, args);
hilog.warn(this.domain, this.prefix, this.format, args);
}

error(...args: string[]): void {
hilog.error(this.domain, this.prefix, this.format, args);
hilog.error(this.domain, this.prefix, this.format, args);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
import { RNPackage,TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
import type { TurboModule, TurboModuleContext} from '@rnoh/react-native-openharmony/ts';
import { RNPackage, TurboModulesFactory } from '@rnoh/react-native-openharmony/ts';
import type { TurboModule, TurboModuleContext } from '@rnoh/react-native-openharmony/ts';
import { TM } from "@rnoh/react-native-openharmony/generated/ts";
import { SQLitePluginTurboModule } from './SQLitePluginTurboModule';
import Logger from './Logger';
import CommonConstants from './CommonConstants';


class SQLitePluginTurboModulesFactory extends TurboModulesFactory{

class SQLitePluginTurboModulesFactory extends TurboModulesFactory {
createTurboModule(name: string): TurboModule | null {
console.info("test--qwf=SQLitePlugin=createTurboModule>>>>>"+name);
Logger.debug(CommonConstants.TAG, "test--SQLitePlugin=createTurboModule>>>>>" + name);
if (name == TM.SQLitePlugin.NAME) {
return new SQLitePluginTurboModule(this.ctx);
}
return null;
}

hasTurboModule(name: string): boolean {
console.info("test--qwf=SQLitePlugin=hasTurboModule>>>>>"+name);
Logger.debug(CommonConstants.TAG, "test--SQLitePlugin=hasTurboModule>>>>>" + name);
return name == TM.SQLitePlugin.NAME;
}
}
export class SQLitePluginPackage extends RNPackage{

export class SQLitePluginPackage extends RNPackage {
createTurboModulesFactory(ctx: TurboModuleContext): TurboModulesFactory {
console.info("test--qwf=SQLitePlugin=createTurboModulesFactory>>>>>");
Logger.debug(CommonConstants.TAG, "test--SQLitePlugin=createTurboModulesFactory>>>>>");
return new SQLitePluginTurboModulesFactory(ctx);
}
}
Loading