エージェント時代の アプリ基盤
JavaScript アプリを
必要に
MIT ライセンスで公開されている、無料のオープンソースです。
# For library projects
npx crossbind build
# For app projects
npx crossbind app upload app-store -p ios
- ブラウザーChrome, Firefox, Safari
- モバイルiOS, Android
crossbind アプリ · React Native - サーバーとエッジNode.js, Cloudflare Workers
- デスクトップmacOS, Linux, Windows
crossbind アプリ · Electron - WASIwasmtime 47+
ネイティブのソースから、あらゆる実行環境へ。
crossbind は C++ と Rust をどこからでも取り込み、すべてのターゲット向けにビルドして、各プラットフォームが読み込むものを npm 用のパッケージにして渡します。
JavaScript から SQLite を使う。
crossbind のライブラリカタログに SQL クエリを実行します。SQLite はブラウザー上で WebAssembly として動きます。
#pragma once
#include <sqlite3.h>
#include <stdexcept>
#include <string>
class Database {
public:
Database() {
if (sqlite3_open(":memory:", &handle) != SQLITE_OK) throw std::runtime_error("cannot open the database");
}
~Database() { sqlite3_close(handle); }
std::string version() { return sqlite3_libversion(); }
void exec(const std::string& sql) { run(sql); }
std::string query(const std::string& sql) {
rows = "[";
run(sql);
rows += "]";
return rows;
}
private:
void run(const std::string& sql) {
char* message = nullptr;
if (sqlite3_exec(handle, sql.c_str(), collect, this, &message) == SQLITE_OK) return;
const std::string reason = message ? message : "unknown error";
sqlite3_free(message);
throw std::runtime_error(reason);
}
static int collect(void* owner, int count, char** values, char** names) {
Database* self = static_cast<Database*>(owner);
if (self->rows.size() > 1) self->rows += ",";
self->rows += "{";
for (int column = 0; column < count; column += 1) {
if (column) self->rows += ",";
self->rows += quote(names[column]) + ":" + (values[column] ? quote(values[column]) : "null");
}
self->rows += "}";
return 0;
}
static std::string quote(const char* text) {
std::string out = "\"";
for (const char* character = text; *character; character += 1) {
if (*character == '"' || *character == '\\') out += '\\';
out += *character;
}
return out + "\"";
}
sqlite3* handle = nullptr;
std::string rows;
};
import { initNative, Database } from './native/database.h';
import { catalogAsSql } from './catalog.js';
await initNative();
const db = await new Database();
await db.exec(catalogAsSql);
const rows = await db.query(`
`);
初回の実行では 1.5 MB の WebAssembly をダウンロードします。プレイグラウンドで試す →