### Build and run the C example Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-c/README.md Compiles the example C file linking against the Cozo C library and executes the resulting binary. ```bash gcc -L../target/release/ -lcozo_c example.c -o example && ./example ``` -------------------------------- ### Run Example Script Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Command to execute the example script after successful build. ```bash node example.js ``` -------------------------------- ### Install cozo-node Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Use npm to install the cozo-node package. ```bash npm install --save cozo-node ``` -------------------------------- ### Start the Cozo server Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Launches the Cozo server in an in-memory, non-persistent mode. ```bash ./cozo server ``` -------------------------------- ### Initialize CozoDB Instances Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Examples for creating both persistent SQLite-based and transient in-memory database instances. ```swift import CozoSwiftBridge { let path = NSHomeDirectory() let file = path + "/cozo-data.db" let db = CozoDB("sqlite", file) let res = try! db.run("?[] <- [[1,2,3]]").toString() } ``` ```swift let db = CozoDB() ``` -------------------------------- ### Launch the Cozo REPL Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Starts the terminal-based interactive REPL for executing CozoScript queries. ```bash ./cozo repl ``` -------------------------------- ### Demonstrate error reporting Source: https://github.com/cozodb/cozo/blob/main/README.md Shows an example of an unbound symbol error in a rule head. ```CozoDB ?[x, Y] := x = 1, y = x + 1 ``` -------------------------------- ### Install Cozo WASM via NPM Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-wasm/README.md Use this command to add the Cozo WASM package to your project dependencies. ```bash npm install cozo-lib-wasm ``` -------------------------------- ### Install CozoSwiftBridge via CocoaPods Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Add the dependency to your Podfile to include the CozoSwiftBridge framework in your target. ```ruby target 'YourApp' do use_frameworks! pod 'CozoSwiftBridge', '~> 0.7.1' end ``` -------------------------------- ### GET /export/{relations} Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Exports data for the specified relations. ```APIDOC ## GET /export/{relations} ### Description Exports data for the specified relations. ### Method GET ### Endpoint /export/{relations} ### Parameters #### Path Parameters - **relations** (String) - Required - A comma-separated list of relations to export. ``` -------------------------------- ### GET /changes/{relation} Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Experimental endpoint to receive changes for a relation via Server-Sent Events. ```APIDOC ## GET /changes/{relation} ### Description Get changes when mutations are made against a relation, relies on SSE. ### Method GET ### Endpoint /changes/{relation} ### Parameters #### Path Parameters - **relation** (String) - Required - The name of the relation to monitor. ``` -------------------------------- ### Initialize and Query CozoDB Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Demonstrates initializing the database and executing CozoScript queries with parameters. ```javascript const {CozoDb} = require('cozo-node') const db = new CozoDb() function printQuery(query, params = {}) { return db.run(query, params) .then(data => console.log(data)) .catch(err => console.error(err.display || err.message)) } printQuery("?[] <- [['hello', 'world!']]") printQuery("?[] <- [['hello', 'world', $name]]", {"name": "JavaScript"}) printQuery("?[a, b] <- [[1, 2]]") ``` -------------------------------- ### Build cozo-node from Source Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Commands to build the native library using the Rust toolchain. ```bash cargo build --release -p cozo-node -F compact -F storage-rocksdb ``` -------------------------------- ### Initialize and Instantiate CozoDb Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-wasm/README.md Import the library and initialize the WASM module before creating a database instance. ```js import init, {CozoDb} from "cozo-lib-wasm"; ``` ```js let db; init().then(() => { db = CozoDb.new(); // db can only be used after the promise resolves }) ``` -------------------------------- ### CozoDB Initialization Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Methods to initialize a new CozoDB instance, either in-memory or backed by a file. ```APIDOC ## init() ### Description Constructs an in-memory database instance. ## init(kind: String, path: String) ### Description Constructs a database instance with a specific engine. ### Parameters - **kind** (String) - Required - The engine kind, can be 'mem' or 'sqlite'. - **path** (String) - Required - The path to the storage file (only used for 'sqlite'). ``` -------------------------------- ### Default build commands for Cozo Swift Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Standard build commands for x86_64 and aarch64 architectures without additional storage engines. ```bash cargo build -p cozo-swift -F compact --target x86_64-apple-darwin --release cargo build -p cozo-swift -F compact --target aarch64-apple-darwin --release ``` -------------------------------- ### CozoDb Constructor Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Initializes a new CozoDb instance with a specified engine and storage path. ```APIDOC ## constructor(engine: string, path: string, options: object) ### Description Creates a new instance of the Cozo database engine. ### Parameters - **engine** (string) - Optional - The database engine to use (e.g., 'mem', 'sqlite', 'rocksdb'). Defaults to 'mem'. - **path** (string) - Optional - The file system path for persistent storage. Defaults to 'data.db'. - **options** (object) - Optional - Configuration options. Defaults to {}. ``` -------------------------------- ### Build CozoDB Binary Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Command to build the cozo-bin package with compact and RocksDB storage features enabled. ```bash cargo build --release -p cozo-bin -F compact -F storage-rocksdb ``` -------------------------------- ### POST /backup Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Backs up the database to a specified path. ```APIDOC ## POST /backup ### Description Backs up the database. ### Method POST ### Endpoint /backup ### Request Body - **path** (String) - Required - The file system path where the backup should be saved. ``` -------------------------------- ### backup(path) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Backs up the current database to a file. ```APIDOC ## backup(path: string) ### Description Creates a backup of the database at the specified file path. ### Parameters - **path** (string) - Required - The destination file path for the backup. ``` -------------------------------- ### Build Cozo C library from source Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-c/README.md Compiles the Cozo C library using Cargo with specific features enabled. ```bash cargo build --release -p cozo_c -F compact -F storage-rocksdb ``` -------------------------------- ### Build the package with maturin Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-python/README.md Use this command to build the package with specific features enabled. ```bash maturin build -F compact -F storage-rocksdb --release ``` -------------------------------- ### POST /import-from-backup Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Imports data into the database from a backup file. ```APIDOC ## POST /import-from-backup ### Description Imports data into the database from a backup. ### Method POST ### Endpoint /import-from-backup ### Request Body - **path** (String) - Required - The path to the backup file. - **relations** (Array) - Required - A list of relation names to import. ``` -------------------------------- ### restore(path) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Restores the database from a backup file. ```APIDOC ## restore(path: string) ### Description Restores the database from a backup file. This operation will fail if the current database is not empty. ### Parameters - **path** (string) - Required - The path to the backup file. ``` -------------------------------- ### Build Cozo for JDK Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-java/README.md Compiles the Java JNI bindings with RocksDB storage support using the Rust toolchain. ```bash cargo build --release -p cozo_java -F storage-rocksdb ``` -------------------------------- ### Build Cozo for Android Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-java/README.md Uses cross-compilation to build the library for multiple Android architectures. ```bash for TARGET in aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android; do cross build -p cozo_java --release --target=$TARGET done ``` -------------------------------- ### CMake build configuration for cozorocks Source: https://github.com/cozodb/cozo/blob/main/cozorocks/CMakeLists.txt Defines the project, sets the C++ standard, includes necessary directories, and adds the cozorocks library. ```cmake cmake_minimum_required(VERSION 3.22) project(cozorocks) set(CMAKE_CXX_STANDARD 17) include_directories("bridge") include_directories("./rocksdb/include") include_directories("../target/cxxbridge") add_library(cozorocks "bridge/bridge.h" "bridge/common.h" "bridge/db.cpp" "bridge/db.h" "bridge/iter.h" "bridge/opts.h" "bridge/slice.h" "bridge/status.cpp" "bridge/status.h" "bridge/tx.cpp" "bridge/tx.h") ``` -------------------------------- ### Import from Backup Request Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md JSON body format required for the POST /import-from-backup endpoint. ```json {"path": , "relations": } ``` -------------------------------- ### Build commands with RocksDB engine enabled Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Modified build commands to include the RocksDB storage engine feature. ```bash cargo build -p cozo-swift -F compact -F storage-rocksdb --target x86_64-apple-darwin --release cargo build -p cozo-swift -F compact -F storage-rocksdb --target aarch64-apple-darwin --release ``` -------------------------------- ### run(script, params) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Executes a CozoScript query against the database. ```APIDOC ## run(script: string, params: object) ### Description Executes a CozoScript query with optional parameters. ### Parameters - **script** (string) - Required - The CozoScript query string. - **params** (object) - Optional - Key-value pairs for query parameters. Defaults to {}. ``` -------------------------------- ### importRelationsFromBackup(path, rels) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Imports specific relations from a backup file. ```APIDOC ## importRelationsFromBackup(path: string, rels: Array) ### Description Imports specific relations from a backup file into the current database. ### Parameters - **path** (string) - Required - The path to the backup file. - **rels** (Array) - Required - The list of relations to import. ``` -------------------------------- ### PUT /import Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Imports data into the database from a JSON body. ```APIDOC ## PUT /import ### Description Imports data into the database. Data should be in application/json MIME type in the body, in the same format as returned in the data field in the /export API. ### Method PUT ### Endpoint /import ``` -------------------------------- ### POST /text-query Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Executes a CozoScript query against the CozoDB server. ```APIDOC ## POST /text-query ### Description Executes a CozoScript query. The server expects a JSON body containing the script and optional parameters. ### Method POST ### Endpoint http://127.0.0.1:9070/text-query ### Parameters #### Query Parameters - **auth** (string) - Optional - Token for authentication when binding to non-loopback addresses. #### Request Body - **script** (string) - Required - The CozoScript query string. - **params** (object) - Optional - Named parameters to be used in the query string. ### Request Example { "script": "?[a, b] := [[1, 2], [3, 4]]", "params": {} } ### Response #### Success Response (200) - **ok** (boolean) - Indicates success. - **rows** (array) - The resulting data rows. - **headers** (array) - The headers for the resulting relation. #### Error Response - **ok** (boolean) - Indicates failure (false). - **message** (string) - The error message. - **display** (string) - A formatted diagnostic message if available. ``` -------------------------------- ### Backup Database Request Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md JSON body format required for the POST /backup endpoint. ```json {"path": } ``` -------------------------------- ### Compile Cozo WASM with wasm-pack Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-wasm/README.md Build command used to generate the WASM module for web targets. ```bash wasm-pack build --target web --release ``` -------------------------------- ### Execute Cozo Queries via Javascript Console Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/src/index.html Use the run function to send queries to the Cozo API. The results are automatically formatted and displayed in a console table. ```javascript let COZO_AUTH = ''; let LAST_RESP = null; async function run(script, params) { const resp = await fetch('/text-query', { method: 'POST', headers: { 'Content-Type': 'application/json', 'x-cozo-auth': COZO_AUTH }, body: JSON.stringify({ script, params: params || {} }) }); if (resp.ok) { const json_resp = await resp.json(); LAST_RESP = json_resp; if (json_resp) { json_resp.headers ||= []; console.table(json_resp.rows.map(row => { let ret = {}; for (let i = 0; i < row.length; ++i) { ret[json_resp.headers[i] || `(${i})`] = row[i]; } return ret })) } } else { console.error((await resp.json()).display) } } console.log( `Welcome to the Cozo Makeshift Javascript Console! You can run your query like this: await run("YOUR QUERY HERE", {param: value}) The global variables 'COZO_AUTH' and 'LAST_RESP' are available.`); ``` -------------------------------- ### POST /text-query Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md Executes a text-based query against the database. ```APIDOC ## POST /text-query ### Description Executes a text-based query against the database. ### Method POST ### Endpoint /text-query ``` -------------------------------- ### Data Management Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Methods for importing, exporting, and managing database state. ```APIDOC ## exportRelations(relations: [String]) ### Description Exports specified relations as JSON. ## importRelations(data: JSON) ### Description Imports data into relations. Note that triggers are not run for the relations. ## backup(path: String) ### Description Backs up the database to a file. ## restore(path: String) ### Description Restores the database from a backup file. ## importRelationsFromBackup(path: String, relations: [String]) ### Description Imports data into a relation from a backup file. ``` -------------------------------- ### Query Execution Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md Methods to execute CozoScript queries against the database. ```APIDOC ## run(query: String) ### Description Executes a CozoScript query against the database. ### Parameters - **query** (String) - Required - The CozoScript to execute. ## run(query: String, params: JSON) ### Description Executes a CozoScript query with parameters against the database. ### Parameters - **query** (String) - Required - The CozoScript to execute. - **params** (JSON) - Required - The parameters for the query in JSON format. ``` -------------------------------- ### Calculate shortest path by distance Source: https://github.com/cozodb/cozo/blob/main/README.md Uses the built-in ShortestPathDijkstra algorithm to find the path with the minimum total distance. ```CozoDB start[] <- [['FRA']] end[] <- [['YPO]] ?[src, dst, distance, path] <~ ShortestPathDijkstra(*route[], start[], end[]) ``` -------------------------------- ### close() Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Closes the database connection and releases native resources. ```APIDOC ## close() ### Description Closes the database instance. This must be called to ensure native resources are properly freed. ``` -------------------------------- ### CozoDb Class Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-wasm/README.md The CozoDb class provides the primary interface for interacting with a Cozo database instance in a web environment. ```APIDOC ## CozoDb.new() ### Description Creates a new instance of the Cozo database. ### Signature `static new(): CozoDb` ## CozoDb.run(script, params) ### Description Executes a CozoScript query with the provided parameters. ### Signature `run(script: string, params: string): string` ## CozoDb.export_relations(data) ### Description Exports relations from the database. ### Signature `export_relations(data: string): string` ## CozoDb.import_relations(data) ### Description Imports relations into the database. Note that triggers are not executed for the imported relations. ### Signature `import_relations(data: string): string` ## CozoDb.free() ### Description Frees the memory associated with the CozoDb instance. ### Signature `free(): void` ``` -------------------------------- ### CozoDB Class API Definition Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-swift/README.md The public interface for the CozoDB class, including methods for query execution, data import/export, and backup/restore operations. ```swift public class CozoDB { public let db: DbInstance /** * Constructs an in-memory database. */ public init(); /** * Constructs a database. * * `kind`: the engine kind, can be `mem` or `sqlite`. * `path`: specifies the path to the storage file, only used for `sqlite` engine */ public init(kind: String, path: String) throws; /** * Run query against the database. * * `query`: the CozoScript to execute. */ public func run(_ query: String) throws -> [NamedRow]; /** * Run query against the database. * * `query`: the CozoScript to execute. * `params`: the params of the query in JSON format. */ public func run(_ query: String, params: JSON) throws -> [NamedRow]; /** * Export relations as JSON * * `relations`: the stored relations to export */ public func exportRelations(relations: [String]) throws -> JSON; /** * Import data into relations * * Note that triggers are _not_ run for the relations, if any exists. * If you need to activate triggers, use queries with parameters. * * `data`: the payload, in the same format as returned by `exportRelations`. */ public func importRelations(data: JSON) throws; /** * Backup the database. * * `path`: path of the output file. */ public func backup(path: String) throws; /** * Restore the database from a backup. * * `path`: path of the input file. */ public func restore(path: String) throws; /** * Import data into a relation from a backup. * * Note that triggers are _not_ run for the relations, if any exists. * If you need to activate triggers, use queries with parameters. * * `path`: path of the input file. * `relations`: the stored relations to import into. */ public func importRelationsFromBackup(path: String, relations: [String]) throws; } ``` -------------------------------- ### Count transitive reachability Source: https://github.com/cozodb/cozo/blob/main/README.md Uses recursive rules to count all airports reachable from a specific origin regardless of the number of stops. ```CozoDB reachable[to] := *route{fr: 'FRA', to} reachable[to] := reachable[stop], *route{fr: stop, to} ?[count_unique(to)] := reachable[to] ``` -------------------------------- ### CozoDb TypeScript API Definition Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-wasm/README.md The interface for interacting with the Cozo database instance. ```ts export class CozoDb { free(): void; static new(): CozoDb; run(script: string, params: string): string; export_relations(data: string): string; // Note that triggers are _not_ run for the relations, if any exists. // If you need to activate triggers, use queries with parameters. import_relations(data: string): string; } ``` -------------------------------- ### importRelations(data) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Imports data into existing relations. ```APIDOC ## importRelations(data: object) ### Description Imports data into existing relations. Note that triggers are not executed during this operation. ### Parameters - **data** (object) - Required - The data object in the format returned by exportRelations. ``` -------------------------------- ### Find longest shortest paths Source: https://github.com/cozodb/cozo/blob/main/README.md Identifies the two most distant airports based on the minimum number of hops required. ```CozoDB shortest_paths[to, shortest(path)] := *route{fr: 'FRA', to}, path = ['FRA', to] shortest_paths[to, shortest(path)] := shortest_paths[stop, prev_path], *route{fr: stop, to}, path = append(prev_path, to) ?[to, path, p_len] := shortest_paths[to, path], p_len = length(path) :order -p_len :limit 2 ``` -------------------------------- ### Count one-stop reachability Source: https://github.com/cozodb/cozo/blob/main/README.md Counts unique airports reachable from a specific origin with exactly one intermediate stop. ```CozoDB ?[count_unique(to)] := *route{fr: 'FRA', to: stop}, *route{fr: stop, to} ``` -------------------------------- ### Count unique connections Source: https://github.com/cozodb/cozo/blob/main/README.md Calculates the number of unique airports directly connected to a specific origin. ```CozoDB ?[count_unique(to)] := *route{fr: 'FRA', to} ``` -------------------------------- ### exportRelations(relations) Source: https://github.com/cozodb/cozo/blob/main/cozo-lib-nodejs/README.md Exports specified relations from the database. ```APIDOC ## exportRelations(relations: Array) ### Description Exports the data of the specified relations. ### Parameters - **relations** (Array) - Required - An array of relation names to export. ``` -------------------------------- ### Query API Request Payload Source: https://github.com/cozodb/cozo/blob/main/cozo-bin/README.md The expected JSON structure for HTTP POST requests to the Cozo query endpoint. ```json { "script": "", "params": {} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.