@capgo/capacitor-fast-sql 8.0.25 → 8.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -19,7 +19,7 @@ import java.util.Map;
19
19
  @CapacitorPlugin(name = "CapgoCapacitorFastSql")
20
20
  public class CapgoCapacitorFastSqlPlugin extends Plugin {
21
21
 
22
- private final String pluginVersion = "8.0.25";
22
+ private final String pluginVersion = "8.0.26";
23
23
 
24
24
  private Map<String, DatabaseConnection> databases = new HashMap<>();
25
25
  private SQLHTTPServer server;
@@ -11,6 +11,9 @@ import fi.iki.elonen.NanoHTTPD; // Note: org.nanohttpd:nanohttpd:2.3.1 still use
11
11
  import java.io.IOException;
12
12
  import java.security.SecureRandom;
13
13
  import java.util.Map;
14
+ import java.util.concurrent.ExecutionException;
15
+ import java.util.concurrent.ExecutorService;
16
+ import java.util.concurrent.Executors;
14
17
  import org.json.JSONArray;
15
18
  import org.json.JSONObject;
16
19
 
@@ -25,6 +28,12 @@ public class SQLHTTPServer extends NanoHTTPD {
25
28
  private final String token;
26
29
  private final Map<String, DatabaseConnection> databases;
27
30
  private final Gson gson = new Gson();
31
+ private final ExecutorService requestExecutor = Executors.newSingleThreadExecutor((runnable) -> {
32
+ Thread thread = new Thread(runnable);
33
+ thread.setName("FastSQL-DB");
34
+ thread.setDaemon(true);
35
+ return thread;
36
+ });
28
37
 
29
38
  public SQLHTTPServer(Map<String, DatabaseConnection> databases) throws IOException {
30
39
  super(findAvailablePort());
@@ -48,6 +57,12 @@ public class SQLHTTPServer extends NanoHTTPD {
48
57
  return response;
49
58
  }
50
59
 
60
+ @Override
61
+ public void stop() {
62
+ super.stop();
63
+ requestExecutor.shutdownNow();
64
+ }
65
+
51
66
  @Override
52
67
  public Response serve(IHTTPSession session) {
53
68
  if (Method.OPTIONS.equals(session.getMethod())) {
@@ -69,25 +84,34 @@ public class SQLHTTPServer extends NanoHTTPD {
69
84
  return addCorsHeaders(newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "Database not found"));
70
85
  }
71
86
 
87
+ try {
88
+ return requestExecutor.submit(() -> routeRequest(session, db)).get();
89
+ } catch (ExecutionException e) {
90
+ Throwable cause = e.getCause();
91
+ String message = cause != null ? cause.getMessage() : e.getMessage();
92
+ return addCorsHeaders(newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Error: " + message));
93
+ } catch (InterruptedException e) {
94
+ Thread.currentThread().interrupt();
95
+ return addCorsHeaders(newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Request interrupted"));
96
+ }
97
+ }
98
+
99
+ private Response routeRequest(IHTTPSession session, DatabaseConnection db) throws Exception {
72
100
  String uri = session.getUri();
73
101
  Method method = session.getMethod();
74
102
 
75
- try {
76
- if (method == Method.POST && uri.equals("/execute")) {
77
- return addCorsHeaders(handleExecute(session, db));
78
- } else if (method == Method.POST && uri.equals("/batch")) {
79
- return addCorsHeaders(handleBatch(session, db));
80
- } else if (method == Method.POST && uri.equals("/transaction/begin")) {
81
- return addCorsHeaders(handleBeginTransaction(db));
82
- } else if (method == Method.POST && uri.equals("/transaction/commit")) {
83
- return addCorsHeaders(handleCommitTransaction(db));
84
- } else if (method == Method.POST && uri.equals("/transaction/rollback")) {
85
- return addCorsHeaders(handleRollbackTransaction(db));
86
- } else {
87
- return addCorsHeaders(newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "Endpoint not found"));
88
- }
89
- } catch (Exception e) {
90
- return addCorsHeaders(newFixedLengthResponse(Response.Status.INTERNAL_ERROR, "text/plain", "Error: " + e.getMessage()));
103
+ if (method == Method.POST && uri.equals("/execute")) {
104
+ return addCorsHeaders(handleExecute(session, db));
105
+ } else if (method == Method.POST && uri.equals("/batch")) {
106
+ return addCorsHeaders(handleBatch(session, db));
107
+ } else if (method == Method.POST && uri.equals("/transaction/begin")) {
108
+ return addCorsHeaders(handleBeginTransaction(db));
109
+ } else if (method == Method.POST && uri.equals("/transaction/commit")) {
110
+ return addCorsHeaders(handleCommitTransaction(db));
111
+ } else if (method == Method.POST && uri.equals("/transaction/rollback")) {
112
+ return addCorsHeaders(handleRollbackTransaction(db));
113
+ } else {
114
+ return addCorsHeaders(newFixedLengthResponse(Response.Status.NOT_FOUND, "text/plain", "Endpoint not found"));
91
115
  }
92
116
  }
93
117
 
@@ -10,7 +10,7 @@ import SQLite3
10
10
  */
11
11
  @objc(CapgoCapacitorFastSqlPlugin)
12
12
  public class CapgoCapacitorFastSqlPlugin: CAPPlugin, CAPBridgedPlugin {
13
- private let pluginVersion: String = "8.0.25"
13
+ private let pluginVersion: String = "8.0.26"
14
14
  public let identifier = "CapgoCapacitorFastSqlPlugin"
15
15
  public let jsName = "CapgoCapacitorFastSql"
16
16
  public let pluginMethods: [CAPPluginMethod] = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-fast-sql",
3
- "version": "8.0.25",
3
+ "version": "8.0.26",
4
4
  "description": "High-performance native SQLite plugin with custom protocol for efficient sync operations and IndexedDB replacement",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",