Skip to content

Commit

Permalink
libsql dylib option. wip OP-Engineering#203
Browse files Browse the repository at this point in the history
  • Loading branch information
jmatsushita committed Dec 13, 2024
1 parent 899a507 commit 09ea6ae
Show file tree
Hide file tree
Showing 13 changed files with 1,638 additions and 1,332 deletions.
12 changes: 6 additions & 6 deletions example/ios/OPSQLiteExample.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
13B07FBC1A68108700A75B9A /* AppDelegate.mm in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB01A68108700A75B9A /* AppDelegate.mm */; };
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
55C40F8AA9DF83E899E3CDAC /* libPods-OPSQLiteExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = D9241EC58491DCDC9B61B00F /* libPods-OPSQLiteExample.a */; };
81AB9BB82411601600AC10FF /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */; };
92B54B8E74B0B43081C567EF /* PrivacyInfo.xcprivacy in Resources */ = {isa = PBXBuildFile; fileRef = 2C08DBE2BF8FD676ED5D600B /* PrivacyInfo.xcprivacy */; };
AC1DF06E9759460CAA51B7B1 /* sample2.sqlite in Resources */ = {isa = PBXBuildFile; fileRef = 9218E48CFB1F478CAC374D68 /* sample2.sqlite */; };
E7DEF1FE8BDF9765E723E132 /* Pods_OPSQLiteExample.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1C7A9DE92F858E1CADC7050A /* Pods_OPSQLiteExample.framework */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -24,13 +24,13 @@
13B07FB51A68108700A75B9A /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; name = Images.xcassets; path = OPSQLiteExample/Images.xcassets; sourceTree = "<group>"; };
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = OPSQLiteExample/Info.plist; sourceTree = "<group>"; };
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = OPSQLiteExample/main.m; sourceTree = "<group>"; };
1C7A9DE92F858E1CADC7050A /* Pods_OPSQLiteExample.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_OPSQLiteExample.framework; sourceTree = BUILT_PRODUCTS_DIR; };
2C08DBE2BF8FD676ED5D600B /* PrivacyInfo.xcprivacy */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xml; name = PrivacyInfo.xcprivacy; path = OPSQLiteExample/PrivacyInfo.xcprivacy; sourceTree = "<group>"; };
3B4392A12AC88292D35C810B /* Pods-OPSQLiteExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OPSQLiteExample.debug.xcconfig"; path = "Target Support Files/Pods-OPSQLiteExample/Pods-OPSQLiteExample.debug.xcconfig"; sourceTree = "<group>"; };
5709B34CF0A7D63546082F79 /* Pods-OPSQLiteExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-OPSQLiteExample.release.xcconfig"; path = "Target Support Files/Pods-OPSQLiteExample/Pods-OPSQLiteExample.release.xcconfig"; sourceTree = "<group>"; };
81AB9BB72411601600AC10FF /* LaunchScreen.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; name = LaunchScreen.storyboard; path = OPSQLiteExample/LaunchScreen.storyboard; sourceTree = "<group>"; };
9218E48CFB1F478CAC374D68 /* sample2.sqlite */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = sample2.sqlite; path = ../assets/sqlite/sample2.sqlite; sourceTree = "<group>"; };
96FD9FD0FC4F4540AC7A9CE6 /* sample.sqlite */ = {isa = PBXFileReference; explicitFileType = undefined; fileEncoding = 9; includeInIndex = 0; lastKnownFileType = unknown; name = sample.sqlite; path = ../assets/sample.sqlite; sourceTree = "<group>"; };
D9241EC58491DCDC9B61B00F /* libPods-OPSQLiteExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-OPSQLiteExample.a"; sourceTree = BUILT_PRODUCTS_DIR; };
ED297162215061F000B7C4FE /* JavaScriptCore.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = JavaScriptCore.framework; path = System/Library/Frameworks/JavaScriptCore.framework; sourceTree = SDKROOT; };
/* End PBXFileReference section */

Expand All @@ -39,7 +39,7 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
55C40F8AA9DF83E899E3CDAC /* libPods-OPSQLiteExample.a in Frameworks */,
E7DEF1FE8BDF9765E723E132 /* Pods_OPSQLiteExample.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -64,7 +64,7 @@
isa = PBXGroup;
children = (
ED297162215061F000B7C4FE /* JavaScriptCore.framework */,
D9241EC58491DCDC9B61B00F /* libPods-OPSQLiteExample.a */,
1C7A9DE92F858E1CADC7050A /* Pods_OPSQLiteExample.framework */,
);
name = Frameworks;
sourceTree = "<group>";
Expand Down Expand Up @@ -302,7 +302,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 24CMR7378R;
DEVELOPMENT_TEAM = TB6Q4VF626;
ENABLE_BITCODE = NO;
INFOPLIST_FILE = OPSQLiteExample/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "OP SQLite";
Expand Down Expand Up @@ -335,7 +335,7 @@
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
CLANG_ENABLE_MODULES = YES;
CURRENT_PROJECT_VERSION = 1;
DEVELOPMENT_TEAM = 24CMR7378R;
DEVELOPMENT_TEAM = TB6Q4VF626;
INFOPLIST_FILE = OPSQLiteExample/Info.plist;
INFOPLIST_KEY_CFBundleDisplayName = "OP SQLite";
LD_RUNPATH_SEARCH_PATHS = (
Expand Down
3 changes: 3 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ target 'OPSQLiteExample' do
# end
# end

# Support libsql dylib
use_frameworks!

post_install do |installer|
# https://github.com/facebook/react-native/blob/main/packages/react-native/scripts/react_native_pods.rb#L197-L202
react_native_post_install(
Expand Down
4 changes: 2 additions & 2 deletions 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: 06a9c6900587420b90accc394199527c64259db4
op-sqlite: 9917e5a5747fc813e42487c0cbdd2d35eaa687bb
op-sqlite: a9b4634586b224847c0f234bab5afc1fa06160a0
RCT-Folly: bf5c0376ffe4dd2cf438dcf86db385df9fdce648
RCTDeprecation: fb7d408617e25d7f537940000d766d60149c5fea
RCTRequired: 9aaf0ffcc1f41f0c671af863970ef25c422a9920
Expand Down Expand Up @@ -1848,6 +1848,6 @@ SPEC CHECKSUMS:
SocketRocket: d4aabe649be1e368d1318fdf28a022d714d65748
Yoga: fcc198acd4a55599b3468cfb6ebc526baff5f06e

PODFILE CHECKSUM: 737501a1bf4136f64686144938c4ffc7b1cb39b0
PODFILE CHECKSUM: 085a8d2838f4a6cb98648caa7ef0522d5ede52a0

COCOAPODS: 1.15.2
3 changes: 2 additions & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,11 @@
"fts5": true,
"rtree": true,
"libsql": false,
"libsql_dyn": true,
"sqliteVec": true,
"tokenizers": [
"wordtokenizer",
"porter"
]
}
}
}
27 changes: 27 additions & 0 deletions ios/CLibsqlDynamic.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>CLibsqlDynamic.framework/CLibsqlDynamic</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>CLibsqlDynamic.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CLibsql {
header "libsql.h"
export *
}
245 changes: 245 additions & 0 deletions ios/CLibsqlDynamic.xcframework/ios-arm64/Headers/libsql.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,245 @@
#ifndef LIBSQL_H
#define LIBSQL_H

#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>

typedef struct libsql_error_t libsql_error_t;

typedef enum {
LIBSQL_CYPHER_DEFAULT = 0,
LIBSQL_CYPHER_AES256,
} libsql_cypher_t;

typedef enum {
LIBSQL_TYPE_INTEGER = 1,
LIBSQL_TYPE_REAL = 2,
LIBSQL_TYPE_TEXT = 3,
LIBSQL_TYPE_BLOB = 4,
LIBSQL_TYPE_NULL = 5,
} libsql_type_t;

typedef enum {
LIBSQL_TRACING_LEVEL_ERROR = 1,
LIBSQL_TRACING_LEVEL_WARN,
LIBSQL_TRACING_LEVEL_INFO,
LIBSQL_TRACING_LEVEL_DEBUG,
LIBSQL_TRACING_LEVEL_TRACE,
} libsql_tracing_level_t;

typedef struct {
const char *message;
const char *target;
const char *file;
uint64_t timestamp;
size_t line;
libsql_tracing_level_t level;
} libsql_log_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_database_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_connection_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_statement_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_transaction_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_rows_t;

typedef struct {
libsql_error_t *err;
void *inner;
} libsql_row_t;

typedef struct {
libsql_error_t *err;
} libsql_batch_t;

typedef struct {
const void *ptr;
size_t len;
} libsql_slice_t;

typedef union {
int64_t integer;
double real;
libsql_slice_t text;
libsql_slice_t blob;
} libsql_value_union_t;

typedef struct {
libsql_value_union_t value;
libsql_type_t type;
} libsql_value_t;

typedef struct {
libsql_error_t *err;
libsql_value_t ok;
} libsql_result_value_t;

typedef struct {
libsql_error_t *err;
uint64_t frame_no;
uint64_t frames_synced;
} libsql_sync_t;

typedef struct {
libsql_error_t *err;
} libsql_bind_t;

typedef struct {
libsql_error_t *err;
uint64_t rows_changed;
} libsql_execute_t;

typedef struct {
libsql_error_t *err;
int64_t last_inserted_rowid;
uint64_t total_changes;
} libsql_connection_info_t;

/**
* Database description.
*/
typedef struct {
/** The url to the primary database */
const char *url;
/** Path to the database file or `:memory:` */
const char *path;
/** Auth token to access the primary */
const char *auth_token;
/** Encryption key to encrypt and decrypt the database in `path` */
const char *encryption_key;
/** Interval to periodicaly sync with primary */
uint64_t sync_interval;
/** Cypher to be used with `encryption_key` */
libsql_cypher_t cypher;
/** If set, disable `read_your_writes`. To mantain consistency. */
bool disable_read_your_writes;
/** Enable Webpki connector */
bool webpki;
} libsql_database_desc_t;

typedef struct {
void (*logger)(libsql_log_t log);
const char *version;
} libsql_config_t;

/** Setup some global info */
const libsql_error_t *libsql_setup(libsql_config_t config);

/** Get the error message from a error */
const char *libsql_error_message(libsql_error_t *self);

/** Create or open a database */
libsql_database_t libsql_database_init(libsql_database_desc_t desc);

/** Sync frames with the primary */
libsql_sync_t libsql_database_sync(libsql_database_t self);

/** Connect with the database */
libsql_connection_t libsql_database_connect(libsql_database_t self);

/** Begin a transaction */
libsql_transaction_t libsql_connection_transaction(libsql_connection_t self);

/** Send a batch statement in a connection */
libsql_batch_t
libsql_connection_batch(libsql_connection_t self, const char *sql);

/** Send a batch statement in a connection */
libsql_connection_info_t libsql_connection_info(libsql_connection_t self);

/** Send a batch statement in a transaction */
libsql_batch_t
libsql_transaction_batch(libsql_transaction_t self, const char *sql);

/** Prepare a statement in a connection */
libsql_statement_t
libsql_connection_prepare(libsql_connection_t self, const char *sql);
/** Prepare a statement in a transaction */
libsql_statement_t
libsql_transaction_prepare(libsql_transaction_t self, const char *sql);

/** Execute a statement */
libsql_execute_t libsql_statement_execute(libsql_statement_t self);
/** Query a statement */
libsql_rows_t libsql_statement_query(libsql_statement_t self);
/** Reset a statement */
void libsql_statement_reset(libsql_statement_t self);
/** Column count */
size_t libsql_statement_column_count(libsql_statement_t self);

/** Get the next row from rows */
libsql_row_t libsql_rows_next(libsql_rows_t self);
/** Get the column name at the index */
libsql_slice_t libsql_rows_column_name(libsql_rows_t self, int32_t index);
/** Get rows column count */
int32_t libsql_rows_column_length(libsql_rows_t self);

/** Get the value at the the index */
libsql_result_value_t libsql_row_value(libsql_row_t self, int32_t index);
/** Get the column name at the the index */
libsql_slice_t libsql_row_name(libsql_row_t self, int32_t index);
/** Get row column count */
int32_t libsql_row_length(libsql_row_t self);
/** Check if the row is empty, indicating the end of `libsql_rows_next` */
bool libsql_row_empty(libsql_row_t self);

/** Bind a named argument to a statement */
libsql_bind_t libsql_statement_bind_named(
libsql_statement_t self,
const char *name,
libsql_value_t value
);
/** Bind a positional argument to a statement */
libsql_bind_t
libsql_statement_bind_value(libsql_statement_t self, libsql_value_t value);

/** Create a libsql integer value */
libsql_value_t libsql_integer(int64_t integer);
/** Create a libsql real value */
libsql_value_t libsql_real(double real);
/** Create a libsql text value */
libsql_value_t libsql_text(const char *ptr, size_t len);
/** Create a libsql blob value */
libsql_value_t libsql_blob(const uint8_t *ptr, size_t len);
/** Create a libsql null value */
libsql_value_t libsql_null();

/** Deallocate and close a error */
void libsql_error_deinit(libsql_error_t *self);
/** Deallocate and close a database */
void libsql_database_deinit(libsql_database_t self);
/** Deallocate and close a connection */
void libsql_connection_deinit(libsql_connection_t self);
/** Deallocate and close a statement */
void libsql_statement_deinit(libsql_statement_t self);
/** Deallocate and commit a transaction (transaction becomes invalid) */
void libsql_transaction_commit(libsql_transaction_t self);
/** Deallocate and rollback a transaction (transaction becomes invalid) */
void libsql_transaction_rollback(libsql_transaction_t self);
/** Deallocate and close rows */
void libsql_rows_deinit(libsql_rows_t self);
/** Deallocate and close a row */
void libsql_row_deinit(libsql_row_t self);
/** Deallocate a slice */
void libsql_slice_deinit(libsql_slice_t value);

#endif /* LIBSQL_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module CLibsql {
header "libsql.h"
export *
}
Binary file not shown.
Loading

0 comments on commit 09ea6ae

Please sign in to comment.