Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Merge #181
Browse files Browse the repository at this point in the history
181: JS client: use native fetch when available. r=BearLemma a=BearLemma

Might be fixing #179 
Needs testing though.

Co-authored-by: Jan Plhak <[email protected]>
  • Loading branch information
bors[bot] and BearLemma authored Feb 17, 2023
2 parents 28c2762 + 54ba8b4 commit f8043c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 14 deletions.
5 changes: 5 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions packages/js/libsql-client/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/js/libsql-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"@types/jest": "^29.2.5",
"jest": "^29.3.1",
"prettier": "^2.8.3",
"ts-jest": "^29.0.3",
"ts-jest": "^29.0.5",
"typescript": "^4.9.4"
},
"dependencies": {
Expand Down
10 changes: 6 additions & 4 deletions packages/js/libsql-client/src/lib/driver/HttpDriver.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fetch from "cross-fetch";
import { fetch as crossFetch } from "cross-fetch";
import { ResultSet, BoundStatement, Params } from "../libsql-js";
import { Driver } from "./Driver";

Expand All @@ -25,11 +25,13 @@ export class HttpDriver implements Driver {
}

const statements = buildStatements(["BEGIN", ...stmts, "COMMIT"]);

const response = await fetch(this.url, {
const reqParams = {
method: "POST",
body: JSON.stringify(statements)
});
};

const compatibleFetch = typeof fetch === "function" ? fetch : crossFetch;
const response = await compatibleFetch(this.url, reqParams);
if (response.status === 200) {
const results = await response.json();
validateTopLevelResults(results, statements.statements.length);
Expand Down

0 comments on commit f8043c6

Please sign in to comment.