Skip to content

Commit

Permalink
Modify turbo.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ospfranco committed Dec 1, 2024
1 parent 301bf33 commit 7fc13cd
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 16 deletions.
10 changes: 6 additions & 4 deletions cpp/DBHostObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ void DBHostObject::create_jsi_functions() {
params = to_variant_vec(rt, args[1]);
}
#ifdef OP_SQLITE_USE_LIBSQL
auto status = opsqlite_libsql_execute(db_name, query, &params);
auto status = opsqlite_libsql_execute(db_name, query, &params);
#else
auto status = opsqlite_execute(db_name, query, &params);
#endif
Expand Down Expand Up @@ -888,9 +888,11 @@ jsi::Value DBHostObject::get(jsi::Runtime &rt,
const jsi::PropNameID &propNameID) {
auto name = propNameID.utf8(rt);
if (function_map.count(name) != 1) {
return HOSTFN(name.c_str()) {
throw std::runtime_error("[op-sqlite] Function " + name + " not implemented for current backend (libsql or sqlcipher)");
});
return HOSTFN(name.c_str()) {
throw std::runtime_error(
"[op-sqlite] Function " + name +
" not implemented for current backend (libsql or sqlcipher)");
});
}

return jsi::Value(rt, function_map[name]);
Expand Down
2 changes: 1 addition & 1 deletion example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1785,7 +1785,7 @@ SPEC CHECKSUMS:
GCDWebServer: 2c156a56c8226e2d5c0c3f208a3621ccffbe3ce4
glog: 08b301085f15bcbb6ff8632a8ebaf239aae04e6a
hermes-engine: 46f1ffbf0297f4298862068dd4c274d4ac17a1fd
op-sqlite: fc35cf9d2d0ace5c5b7189e2ccadcfbb80e6e6f5
op-sqlite: 9917e5a5747fc813e42487c0cbdd2d35eaa687bb
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
RCTDeprecation: fde92935b3caa6cb65cbff9fbb7d3a9867ffb259
RCTRequired: 75c6cee42d21c1530a6f204ba32ff57335d19007
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"iosSqlite": false,
"fts5": true,
"rtree": true,
"libsql": true,
"libsql": false,
"sqliteVec": true,
"tokenizers": [
"wordtokenizer",
Expand Down
23 changes: 15 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export const {
? NativeModules.OPSQLite.getConstants()
: NativeModules.OPSQLite;

type Scalar = string | number | boolean | null | ArrayBuffer | ArrayBufferView;

/**
* Object returned by SQL Query executions {
* insertId: Represent the auto-generated row id if applicable
Expand All @@ -59,9 +61,9 @@ export type QueryResult = {
insertId?: number;
rowsAffected: number;
res?: any[];
rows: Array<Record<string, string | number | boolean | ArrayBufferLike>>;
rows: Array<Record<string, Scalar>>;
// An array of intermediate results, just values without column names
rawRows?: any[];
rawRows?: Scalar[][];
columnNames?: string[];
/**
* Query metadata, available only for select query results
Expand Down Expand Up @@ -112,7 +114,7 @@ export interface FileLoadResult extends BatchQueryResult {

export interface Transaction {
commit: () => Promise<QueryResult>;
execute: (query: string, params?: any[]) => Promise<QueryResult>;
execute: (query: string, params?: Scalar[]) => Promise<QueryResult>;
rollback: () => Promise<QueryResult>;
}

Expand Down Expand Up @@ -274,7 +276,10 @@ function enhanceDB(db: DB, options: any): DB {

return result;
},
executeSync: (query: string, params?: any[] | undefined): QueryResult => {
executeSync: (
query: string,
params?: Scalar[] | undefined
): QueryResult => {
const sanitizedParams = params?.map((p) => {
if (ArrayBuffer.isView(p)) {
return p.buffer;
Expand All @@ -286,10 +291,11 @@ function enhanceDB(db: DB, options: any): DB {
let intermediateResult = db.executeSync(query, sanitizedParams);
let rows: any[] = [];
for (let i = 0; i < (intermediateResult.rawRows?.length ?? 0); i++) {
let row: any = {};
let row: Record<string, Scalar> = {};
let rawRow = intermediateResult.rawRows![i]!;
for (let j = 0; j < intermediateResult.columnNames!.length; j++) {
let columnName = intermediateResult.columnNames![j]!;
let value = intermediateResult.rawRows![i][j];
let value = rawRow[j]!;

row[columnName] = value;
}
Expand All @@ -307,7 +313,7 @@ function enhanceDB(db: DB, options: any): DB {
},
execute: async (
query: string,
params?: any[] | undefined
params?: Scalar[] | undefined
): Promise<QueryResult> => {
const sanitizedParams = params?.map((p) => {
if (ArrayBuffer.isView(p)) {
Expand All @@ -322,9 +328,10 @@ function enhanceDB(db: DB, options: any): DB {
let rows: any[] = [];
for (let i = 0; i < (intermediateResult.rawRows?.length ?? 0); i++) {
let row: any = {};
let rawRow = intermediateResult.rawRows![i]!;
for (let j = 0; j < intermediateResult.columnNames!.length; j++) {
let columnName = intermediateResult.columnNames![j]!;
let value = intermediateResult.rawRows![i][j];
let value = rawRow[j]!;

row[columnName] = value;
}
Expand Down
6 changes: 4 additions & 2 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"src/tests/*.ts",
"example/package.json",
"example/android",
"cpp",
"cpp/*.cpp",
"cpp/*.h",
"!example/android/.gradle",
"!example/android/build",
"!example/android/app/build"
Expand All @@ -22,7 +23,8 @@
"package.json",
"*.podspec",
"ios",
"cpp",
"cpp/*.cpp",
"cpp/*.h",
"src/*.ts",
"src/tests/*.ts",
"example/package.json",
Expand Down

0 comments on commit 7fc13cd

Please sign in to comment.