### Install DefraDB from Source Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Instructions to clone the DefraDB repository and build the executable locally using the Go toolchain and make command. ```shell git clone git@github.com/sourcenetwork/defradb.git cd defradb make install ``` -------------------------------- ### Start DefraDB Node with Pubsub Peering Configuration Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Command to start a second DefraDB node (nodeB) with custom configurations for its root directory, client API URL, P2P address, gRPC address, and a list of peer multiaddresses for pubsub synchronization. This example connects nodeB to nodeA. ```shell defradb start --rootdir ~/.defradb-nodeB --url localhost:9182 --p2paddr /ip4/0.0.0.0/tcp/9172 --tcpaddr /ip4/0.0.0.0/tcp/9162 --peers /ip4/0.0.0.0/tcp/9171/p2p/12D3KooWNXm3dmrwCYSxGoRUyZstaKYiHPdt8uZH5vgVaEJyzU8B ``` -------------------------------- ### Start DefraDB Node for Replication (nodeB) Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Starts `nodeB`, configured to receive updates from `nodeA`. It specifies a different root directory, URL, and P2P/TCP addresses to run concurrently with `nodeA`. ```shell defradb start --rootdir ~/.defradb-nodeB --url localhost:9182 --p2paddr /ip4/0.0.0.0/tcp/9172 --tcpaddr /ip4/0.0.0.0/tcp/9162 ``` -------------------------------- ### Start DefraDB Node with Default Configuration Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Command to start a DefraDB node using its default configuration. This initiates the node and outputs its Peer ID, which is necessary for other nodes to connect. ```shell defradb start ``` -------------------------------- ### Clone and Start DefraDB Project Source: https://github.com/sourcenetwork/defradb/blob/develop/CONTRIBUTING.md This snippet provides the shell commands to clone the DefraDB repository, navigate into its directory, and start the project. It's the initial setup required for local development. ```shell git clone https://github.com/sourcenetwork/defradb.git cd defradb make start ``` -------------------------------- ### Start DefraDB Node for Replication (nodeA) Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Initiates a DefraDB node, `nodeA`, which will act as the source for active replication to another node. This is the first step in setting up targeted data synchronization. ```shell defradb start ``` -------------------------------- ### Start DefraDB with Badger Store Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Launches the DefraDB database instance, configuring it to use the Badger key-value store for data persistence. ```Shell defradb start --store badger ``` -------------------------------- ### Start DefraDB with TLS using Custom Certificate Paths Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Starts DefraDB with TLS enabled, specifying custom paths for the public and private key files. This is used when certificates are not stored in the default location. ```shell defradb start --tls --pubkeypath ~/path-to-pubkey.key --privkeypath ~/path-to-privkey.crt ``` -------------------------------- ### Start DefraDB with Self-Signed TLS Certificates Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Launches DefraDB with TLS enabled, using self-signed certificates located in the default `~/.defradb/certs/` directory. This secures the HTTP API endpoint. ```shell defradb start --tls ``` -------------------------------- ### Add DefraDB to PATH Environment Variable Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Command to add the Go toolchain's binary directory to the system's PATH environment variable, ensuring the `defradb` executable is accessible from any directory. ```shell export PATH=$PATH:$(go env GOPATH)/bin ``` -------------------------------- ### Start DefraDB with Custom Root Directory Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Starts DefraDB, overriding the default root directory to store data and configurations at a specified path. ```Shell defradb --rootdir start ``` -------------------------------- ### Subscribe to DefraDB Collection Updates using Shell Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Demonstrates how to subscribe to updates on a DefraDB collection using its `schemaVersionID` as a pubsub topic. This allows a node to receive real-time updates from another node for a specific collection. ```shell defradb client rpc p2pcollection add --url localhost:9182 bafkreibpnvkvjqvg4skzlijka5xe63zeu74ivcjwd76q7yi65jdhwqhske ``` ```shell defradb client rpc p2pcollection add --url localhost:9182 ``` -------------------------------- ### Configure Active Replication from NodeA to NodeB for Article Collection Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Configures `nodeA` to actively push updates of the `Article` collection to `nodeB`. This involves adding `nodeB` as a replicator peer and then setting the specific collection for replication. ```shell defradb client rpc addreplicator "Article" /ip4/0.0.0.0/tcp/9172/p2p/ dedfradb client rpc replicator set -c "Article" /ip4/0.0.0.0/tcp/9172/p2p/ ``` -------------------------------- ### Basic DefraDB Start Command Usage Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_start.md This snippet illustrates the fundamental command structure for starting a DefraDB node, indicating that various flags can be appended to customize its behavior. ```Shell defradb start [flags] ``` -------------------------------- ### Developing DefraDB Playground Source: https://github.com/sourcenetwork/defradb/blob/develop/playground/README.md Installs project dependencies and starts a local development server for the DefraDB Playground application, typically bound to localhost:5173. ```bash npm install npm run dev ``` -------------------------------- ### Clone DefraDB Repository Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Downloads the DefraDB source code from GitHub to your local machine. ```Shell git clone https://github.com/sourcenetwork/defradb ``` -------------------------------- ### Execute Explain GraphQL Query Example Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/explain-systems.md A GraphQL query demonstrating the use of the `@explain(type: execute)` directive to perform an Execute Explain on the 'Author' collection, retrieving 'name' and 'age'. ```graphql query @explain(type: execute) { Author { name age } } ``` -------------------------------- ### Create a User Document in DefraDB Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md A `defradb client query` command executing a GraphQL mutation request to create a new document of the `User` type with specified field values. The command returns the unique `_docID` for the newly created document. ```shell defradb client query ' mutation { create_User(input: {age: 31, verified: true, points: 90, name: "Bob"}) { _docID } } ' ``` -------------------------------- ### Start and Verify a DefraDB Node Source: https://github.com/sourcenetwork/defradb/blob/develop/README.md Executes the `defradb start` command to launch a DefraDB node. It is recommended to keep the node running for subsequent examples. A separate command `defradb client collection describe` can be used in another terminal to verify the local connection to the running node. ```shell defradb start ``` ```shell defradb client collection describe ``` -------------------------------- ### defradb client p2p replicator set example Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_p2p_replicator_set.md Example command to add a replicator for the 'Users' collection, specifying a peer ID and its network addresses for synchronization. ```bash defradb client p2p replicator set -c Users '{"ID": "12D3", "Addrs": ["/ip4/0.0.0.0/tcp/9171"]}' ``` -------------------------------- ### DefraDB Start Command Specific Options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_start.md This section details the command-line options specific to the 'defradb start' command. These options allow for fine-grained control over the DefraDB node's operation, including CORS settings, DAC engine selection, key generation, development features, transaction retries, encryption, P2P networking, commit signing, telemetry, P2P addresses, peer connections, TLS paths, replicator retry intervals, datastore type, and value log file size. ```APIDOC --allowed-origins stringArray: List of origins to allow for CORS requests --dac-type string: Specify the document acp engine to use (supported: none (default), local, source-hub) --default-key-type string: Default key type to generate new node identity if one doesn't exist in the keyring. Valid values are 'secp256k1' and 'ed25519'. If not specified, the default key type will be 'secp256k1'. (default "secp256k1") --development: Enables a set of features that make development easier but should not be enabled in production: - allows purging of all persisted data - generates temporary node identity if keyring is disabled -h, --help: help for start --max-txn-retries int: Specify the maximum number of retries per transaction (default 5) --no-encryption: Skip generating an encryption key. Encryption at rest will be disabled. WARNING: This cannot be undone. --no-p2p: Disable the peer-to-peer network synchronization system --no-signing: Disable signing of commits. --no-telemetry: Disables telemetry reporting. Telemetry is only enabled in builds that use the telemetry flag. --p2paddr strings: Listen addresses for the p2p network (formatted as a libp2p MultiAddr) (default [/ip4/127.0.0.1/tcp/9171]) --peers stringArray: List of peers to connect to --privkeypath string: Path to the private key for tls --pubkeypath string: Path to the public key for tls --replicator-retry-intervals ints: Retry intervals for the replicator. Format is a comma-separated list of whole number seconds. Example: 10,20,40,80,160,320 (default [30,60,120,240,480,960,1920]) --store string: Specify the datastore to use (supported: badger, memory) (default "badger") --valuelogfilesize int: Specify the datastore value log file size (in bytes). In memory size will be 2*valuelogfilesize (default 1073741824) ``` -------------------------------- ### Build DefraDB Binary Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Executes the Make command to compile DefraDB locally with default configurations. ```Make make ``` -------------------------------- ### Install DefraDB from Source Source: https://github.com/sourcenetwork/defradb/blob/develop/README.md Instructions to clone the DefraDB repository, navigate into the directory, and build/install the executable locally using the Go toolchain. This makes the 'defradb' command available on your system. ```sh git clone git@github.com:sourcenetwork/defradb.git cd defradb make install ``` -------------------------------- ### Add Article Schema to DefraDB Node (nodeB) Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Adds the same `Article` schema definition to `nodeB` as was added to `nodeA`. This ensures both nodes have a consistent schema for the replicated data. ```shell defradb client schema add --url localhost:9182 ' type Article { content: String published: Boolean } ' ``` -------------------------------- ### Add Article Schema to DefraDB Node (nodeA) Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Adds a new `Article` schema definition to `nodeA`. This schema defines the structure of documents that will be replicated to `nodeB`. ```shell defradb client schema add ' type Article { content: String published: Boolean } ' ``` -------------------------------- ### Simple Explain Request for Author Query in GraphQL Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/explain-systems.md This example demonstrates how to use the `@explain` directive in a GraphQL query to obtain a Simple Explain request. This mode returns the syntactic and structural information of the Plan Graph, its nodes, and attributes, without executing the query, providing transparency into DefraDB's internal processing. ```graphql query @explain { Author { name age } } ``` ```json { "explain": { "select TopNode": { "selectNode": { "filter": null, "scanNode": { "filter":null, "collectionID": "3", "collectionName": "Author", "spans": [{ "start": "/3", "end": "/4" }] } } } } } ``` -------------------------------- ### Install humanbench for Go benchmark readability Source: https://github.com/sourcenetwork/defradb/blob/develop/tests/bench/acp/acp_bench_report_20250120.md Provides the command to install `humanbench`, a utility that enhances the readability of `go bench` command outputs. This tool is a prerequisite for understanding the benchmark results presented in this report. ```Shell go install github.com/kevinburke/humanbench@latest ``` -------------------------------- ### defradb keyring export example Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_keyring_export.md An example of how to export an encryption key using the `defradb keyring export` command. ```CLI defradb keyring export encryption-key ``` -------------------------------- ### DefraDB CLI: Create Secondary Index Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_index_create.md Illustrative examples demonstrating how to create secondary indexes on DefraDB collections using the `defradb client index create` command, including basic, named, and unique indexes with custom field ordering. ```CLI defradb client index create --collection Users --fields name ``` ```CLI defradb client index create --collection Users --fields name --name UsersByName ``` ```CLI defradb client index create --collection Users --fields name:ASC,age:DESC --unique ``` -------------------------------- ### Enable Automatic HTTPS for DefraDB with Let's Encrypt Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Configures DefraDB to use automatic HTTPS via Let's Encrypt, requiring open ports 80 and 443, a valid domain, and an email address. This is suitable for public web deployments. ```shell sudo defradb start --tls --url=your-domain.net --email=email@example.com ``` -------------------------------- ### Start DefraDB Node with Default P2P Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/peer-to-peer.md Starts a DefraDB node, automatically initializing a libp2p host and displaying its P2P address and Peer ID. This is the default behavior for node startup. ```bash $ defradb start ``` -------------------------------- ### Query All User Documents in DefraDB Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md A `defradb client query` command executing a GraphQL query to retrieve all documents of the `User` type, returning only the specified fields: `_docID`, `age`, `name`, and `points`. ```shell defradb client query ' query { User { _docID age name points } } ' ``` -------------------------------- ### Examples for defradb client collection describe Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_collection_describe.md Illustrative examples demonstrating how to use `defradb client collection describe` to view collections by different criteria, including all collections, by name, by collection ID, and by version ID. ```CLI defradb client collection describe deffradb client collection describe --name User deffradb client collection describe --collection-id bae123 deffradb client collection describe --version-id bae123 ``` -------------------------------- ### Add User Schema Type to DefraDB Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Command to add a GraphQL-like schema definition for a `User` type to DefraDB. This action generates typed GraphQL endpoints for querying, mutation, and introspection based on the defined schema. ```shell defradb client schema add ' type User { name: String age: Int verified: Boolean points: Float } ' ``` -------------------------------- ### Example Go DocList with Extra Fields Source: https://github.com/sourcenetwork/defradb/blob/develop/tests/predefined/README.md This Go `gen.DocsList` example represents an input document list for the `User` collection. It includes fields such as `age`, `verified`, `email`, `year`, `type`, and `address` which are not defined in the corresponding GraphQL schema, illustrating a `DocList` that is a superset of the schema. ```go gen.DocsList{ ColName: "User", Docs: []map[string]any{ { "name": "Shahzad", "age": 20, "verified": false, "email": "shahzad@gmail.com", "devices": []map[string]any{ { "model": "iPhone Xs", "year": 2022, "type": "phone", }}, "address": map[string]any{ "city": "Munich", }, }}, } ``` -------------------------------- ### Building DefraDB Playground for Production Source: https://github.com/sourcenetwork/defradb/blob/develop/playground/README.md Installs project dependencies and creates a static production build of the DefraDB Playground application. The output files are generated and placed in the `./dist` directory. ```bash npm install npm run build ``` -------------------------------- ### Compile DefraDB Playground Dependencies Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Compiles the necessary dependencies for the DefraDB playground, generating a bundle file in the 'dist' folder. ```Make make deps:playground ``` -------------------------------- ### defradb keyring list command syntax Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_keyring_list.md Provides the general syntax for the `defradb keyring list` command, indicating that it can be used with various flags. An example usage is `defradb keyring list`. ```CLI defradb keyring list [flags] ``` -------------------------------- ### Query DefraDB for Latest Document Commits Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Demonstrates how to query DefraDB using the `defradb client query` command to retrieve the most recent commits for a specific document identified by its document key. The query fetches the commit's CID, delta, height, and linked subgraph commits. ```shell defradb client query ' query { latestCommits(dockey: "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab") { cid delta height links { cid name } } } ' ``` -------------------------------- ### Start DefraDB Node and Connect to Specific Peer Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/peer-to-peer.md Starts a DefraDB node and instructs it to connect to a specified peer using its multi-address. This is used to establish a connection for replication purposes. ```bash $ defradb start --peers /ip4/0.0.0.0/tcp/9171/p2p/ ``` -------------------------------- ### Example: Add View with GraphQL Query, SDL, and Lens Transform Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_view_add.md Provides a concrete example of using `defradb client view add` to define a view named 'Foo' with specific fields, a corresponding GraphQL type definition, and a JSON object for lens configuration, demonstrating how to pass these as string arguments. ```Shell defradb client view add 'Foo { name, ...}' 'type Foo { ... }' '{\"lenses\": [...' ``` -------------------------------- ### Rust Implementation of a DefraDB Lens Module Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/schema-migration.md Provides a Rust code example demonstrating the implementation of a bi-directional Lens module for DefraDB. It includes the `alloc`, `set_param`, and `transform` functions, showing how to handle parameters, memory allocation, and data transformation, along with necessary imports and error handling for a schema migration. ```Rust #[link(wasm_import_module = "lens")] extern "C" { fn next() -> *mut u8; } #[derive(Deserialize, Clone)] pub struct Parameters { pub src: String, pub dst: String, } static PARAMETERS: RwLock> = RwLock::new(None); #[no_mangle] pub extern fn alloc(size: usize) -> *mut u8 { lens_sdk::alloc(size) } #[no_mangle] pub extern fn set_param(ptr: *mut u8) -> *mut u8 { match try_set_param(ptr) { Ok(_) => lens_sdk::nil_ptr(), Err(e) => lens_sdk::to_mem(lens_sdk::ERROR_TYPE_ID, &e.to_string().as_bytes()) } } fn try_set_param(ptr: *mut u8) -> Result<(), Box> { let parameter = lens_sdk::try_from_mem::(ptr)?; let mut dst = PARAMETERS.write()?; *dst = Some(parameter); Ok(()) } #[no_mangle] pub extern fn transform() -> *mut u8 { match try_transform() { Ok(o) => match o { Some(result_json) => lens_sdk::to_mem(lens_sdk::JSON_TYPE_ID, &result_json), None => lens_sdk::nil_ptr(), EndOfStream => lens_sdk::to_mem(lens_sdk::EOS_TYPE_ID, &[]), }, Err(e) => lens_sdk::to_mem(lens_sdk::ERROR_TYPE_ID, &e.to_string().as_bytes()) } } fn try_transform() -> Result>, Box> { let ptr = unsafe { next() }; let mut input = match lens_sdk::try_from_mem::>(ptr)? { Some(v) => v, ``` -------------------------------- ### Get Help for DefraDB Keyring Commands Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_keyring.md This command displays detailed help information for the `defradb keyring` command, including available options and subcommands. ```shell defradb keyring --help ``` -------------------------------- ### defradb client schema patch Usage Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_schema_patch.md Provides practical examples of how to use `defradb client schema patch` to modify a schema. Examples include patching directly from a JSON string argument, loading a patch from a file, and piping patch content from standard input. ```Shell defradb client schema patch '[{ "op": "add", "path": "...", "value": {...} }]' '{"lenses": [...' defradb client schema patch -p patch.json cat patch.json | defrdb client schema patch - ``` -------------------------------- ### DefraDB Client Query Command Usage Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_query.md Practical examples demonstrating how to send GraphQL queries to DefraDB using the `defradb client query` command. This includes direct query input, reading from a file, using an identity, and piping from standard input. ```shell defradb client query 'query { ... }' ``` ```shell defradb client query -f request.graphql ``` ```shell defradb client query -i 028d53f37a19afb9a0dbc5b4be30c65731479ee8cfa0c9bc8f8bf198cc3c075f -f request.graphql ``` ```shell cat request.graphql | defradb client query - ``` -------------------------------- ### Example Database Objects (JSON) Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/query-specification/sorting-and-ordering.md Provides example JSON data representing 'Author' objects with nested 'books' arrays, used to illustrate sorting scenarios and limitations. ```json [ "Author" { "name": "John Grisham", "books": [ { "title": "A Painted House" }, { "title": "The Guardians" } ] }, "Author" { "name": "John Grisham", "books": [ { "title": "Camino Winds" }, ] }, "Author" { "name": "John LeCare", "books": [ { "title": "Tinker, Tailor, Soldier, Spy"} ] } ] ``` -------------------------------- ### Reverse DefraDB Collection Migration with `defradb client lens down` Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_lens_down.md Examples demonstrating how to reverse a collection migration using the `defradb client lens down` command, supporting input from a string, a file, or standard input. ```bash defradb client lens down --collection 2 '[{"name": "Bob"}]' ``` ```bash defradb client lens down --collection 2 -f documents.json ``` ```bash cat documents.json | defradb client lens down --collection 2 - ``` -------------------------------- ### Example JSON Response for Latest Document Commits Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Illustrative JSON output showing the structure of the data returned when querying for the latest document commits. It includes the commit's content identifier (CID), delta payload, height, and an array of linked CIDs and names. ```json { "data": { "latestCommits": [ { "cid": "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u", "delta": "pGNhZ2UYH2RuYW1lY0JvYmZwb2ludHMYWmh2ZXJpZmllZPU=", "height": 1, "links": [ { "cid": "bafybeiet6foxcipesjurdqi4zpsgsiok5znqgw4oa5poef6qtiby5hlpzy", "name": "age" }, { "cid": "bafybeielahxy3r3ulykwoi5qalvkluojta4jlg6eyxvt7lbon3yd6ignby", "name": "name" }, { "cid": "bafybeia3tkpz52s3nx4uqadbm7t5tir6gagkvjkgipmxs2xcyzlkf4y4dm", "name": "points" }, { "cid": "bafybeia4off4javopmxcdyvr6fgb5clo7m5bblxic5sqr2vd52s6khyksm", "name": "verified" } ] } ] } } ``` -------------------------------- ### Install humanbench for Go Benchmarking Source: https://github.com/sourcenetwork/defradb/blob/develop/tests/bench/acp/acp_bench_report_20250114.md Installs the `humanbench` tool, a prerequisite for making `go bench` results more readable. This command fetches the latest version of the tool. ```Go go install github.com/kevinburke/humanbench@latest ``` -------------------------------- ### DefraDB Identity New Command Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_identity_new.md Examples demonstrating how to generate new identities with different key types using the `defradb identity new` command. By default, secp256k1 is used. ```Shell defradb identity new ``` ```Shell defradb identity new --type ed25519 ``` -------------------------------- ### Examples: Add single and multiple P2P collections Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_p2p_collection_add.md Illustrates how to add a single P2P collection using its ID and how to add multiple collections by providing a comma-separated list of IDs. ```Shell defradb client p2p collection add bae123 ``` ```Shell defradb client p2p collection add bae123,bae456 ``` -------------------------------- ### Navigate to DefraDB Directory Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Changes the current working directory to the newly cloned DefraDB repository. ```Shell cd defradb ``` -------------------------------- ### View Go Code Documentation Locally with pkgsite Source: https://github.com/sourcenetwork/defradb/blob/develop/CONTRIBUTING.md This snippet shows how to install and use `pkgsite` to view Go doc comments as a local website for the DefraDB project. It allows developers to browse the generated code documentation in a web browser. ```shell go install golang.org/x/pkgsite/cmd/pkgsite@latest cd your-path-to/defradb/ pkgsite # open http://localhost:8080/github.com/sourcenetwork/defradb ``` -------------------------------- ### Get a document by ID using defradb client Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_collection_get.md Demonstrates how to retrieve a document from a Defradb collection using its unique document ID and the collection name. This is a basic usage example for public documents. ```Shell defradb client collection get --name User bae-123 ``` -------------------------------- ### Set Go Flags for Playground Build Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/deployment-guide.md Sets the GOFLAGS environment variable to include the 'playground' build tag, enabling playground-specific features during compilation. ```Shell GOFLAGS="-tags=playground" ``` -------------------------------- ### Valid and Invalid DefraDB Policy Expression Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/acp/README.md This section illustrates examples of valid and invalid `expr` values for required permissions within a DefraDB DPI-compliant resource. Expressions must start with the 'owner' relation and use only union set operations ('+') thereafter to maintain DPI status. ```text Invalid Expressions: - expr: owner-owner - expr: owner-reader - expr: owner&reader - expr: owner - reader - expr: ownerMalicious + owner - expr: ownerMalicious - expr: owner_new - expr: reader+owner - expr: reader-owner - expr: reader - owner Valid Expressions: - expr: owner - expr: owner + reader - expr: owner +reader - expr: owner+reader ``` -------------------------------- ### Define Users Collection Schema Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/schema-migration.md Defines a new `Users` collection with an `emailAddress` field using a GraphQL schema definition. This is the initial schema setup for the collection. ```graphql defradb client schema add ' type Users { emailAddress: String } ' ``` -------------------------------- ### DefraDB Inherited Command Options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_start.md This section outlines command-line options that are inherited from parent `defradb` commands. These options provide global configurations for the DefraDB application, including keyring management, logging preferences, root directory settings, and secret file paths. ```APIDOC --keyring-backend string: Keyring backend to use. Options are file or system (default "file") --keyring-namespace string: Service name to use when using the system backend (default "defradb") --keyring-path string: Path to store encrypted keys when using the file backend (default "keys") --log-format string: Log format to use. Options are text or json (default "text") --log-level string: Log level to use. Options are debug, info, error, fatal (default "info") --log-output string: Log output path. Options are stderr or stdout. (default "stderr") --log-overrides string: Logger config overrides. Format ,=,...;,... --log-source: Include source location in logs --log-stacktrace: Include stacktrace in error and fatal logs --no-keyring: Disable the keyring and generate ephemeral keys --no-log-color: Disable colored log output --rootdir string: Directory for persistent data (default: $HOME/.defradb) --secret-file string: Path to the file containing secrets (default ".env") --source-hub-address string: The SourceHub address authorized by the client to make SourceHub transactions on behalf of the actor --url string: URL of HTTP endpoint to listen on or connect to (default "127.0.0.1:9181") ``` -------------------------------- ### Expected Response for User Document Creation Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md The JSON structure showing the expected output after successfully creating a user document, which includes the document's unique identifier (`_docID`). ```json { "data": [ { "_docID": "bae-91171025-ed21-50e3-b0dc-e31bccdfa1ab" } ] } ``` -------------------------------- ### View DefraDB Schemas with `defradb client schema describe` Examples Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_schema_describe.md Demonstrates various ways to use the `defradb client schema describe` command to view schema descriptions, including viewing all schemas, filtering by name, root, or version ID. ```Shell defradb client schema describe ``` ```Shell defradb client schema describe --name User ``` ```Shell defradb client schema describe --root bae123 ``` ```Shell defradb client schema describe --version bae123 ``` -------------------------------- ### Defradb Client P2P Replicator Getall Command Options Reference Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_p2p_replicator_getall.md This section details the command-specific and inherited options available for the `defradb client p2p replicator getall` command. It includes flags for help, identity management, keyring configuration, logging preferences, and network connection settings, along with their types and default values. ```APIDOC Options: -h, --help: help for getall Options inherited from parent commands: -i, --identity string: Hex formatted private key used to authenticate with ACP --keyring-backend string: Keyring backend to use. Options are file or system (default "file") --keyring-namespace string: Service name to use when using the system backend (default "defradb") --keyring-path string: Path to store encrypted keys when using the file backend (default "keys") --log-format string: Log format to use. Options are text or json (default "text") --log-level string: Log level to use. Options are debug, info, error, fatal (default "info") --log-output string: Log output path. Options are stderr or stdout. (default "stderr") --log-overrides string: Logger config overrides. Format ,=,...;,... --log-source: Include source location in logs --log-stacktrace: Include stacktrace in error and fatal logs --no-keyring: Disable the keyring and generate ephemeral keys --no-log-color: Disable colored log output --rootdir string: Directory for persistent data (default: $HOME/.defradb) --secret-file string: Path to the file containing secrets (default ".env") --source-hub-address string: The SourceHub address authorized by the client to make SourceHub transactions on behalf of the actor --tx uint: Transaction ID --url string: URL of HTTP endpoint to listen on or connect to (default "127.0.0.1:9181") ``` -------------------------------- ### defradb client p2p replicator set command synopsis Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_p2p_replicator_set.md Synopsis of the `defradb client p2p replicator set` command, outlining its basic structure, required arguments, and optional flags. ```bash defradb client p2p replicator set [-c, --collection] [flags] ``` -------------------------------- ### Query User Documents with Filter in DefraDB Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md A `defradb client query` command executing a GraphQL query to retrieve `User` documents, applying a filter to return only those where the `points` field is greater than or equal to 50. ```shell defradb client query ' query { User(filter: {points: {_ge: 50}}) { _docID age name points } } ' ``` -------------------------------- ### defradb client view add Command Options Reference Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_view_add.md Comprehensive reference for all command-line options available for `defradb client view add`, including specific flags for view configuration and general options inherited from parent commands for authentication, logging, and directory management. Each option is listed with its short and long form, type, and a brief description. ```APIDOC Options: -f, --file string Lens configuration file -h, --help help for add Options inherited from parent commands: -i, --identity string Hex formatted private key used to authenticate with ACP --keyring-backend string Keyring backend to use. Options are file or system (default "file") --keyring-namespace string Service name to use when using the system backend (default "defradb") --keyring-path string Path to store encrypted keys when using the file backend (default "keys") --log-format string Log format to use. Options are text or json (default "text") --log-level string Log level to use. Options are debug, info, error, fatal (default "info") --log-output string Log output path. Options are stderr or stdout. (default "stderr") --log-overrides string Logger config overrides. Format ,=,...;,... --log-source Include source location in logs --log-stacktrace Include stacktrace in error and fatal logs --no-keyring Disable the keyring and generate ephemeral keys --no-log-color Disable colored log output --rootdir string Directory for persistent data (default: $HOME/.defradb) --secret-file string Path to the file containing secrets (default ".env") --source-hub-address string The SourceHub address authorized by the client to make SourceHub transactions on behalf of the actor --tx uint Transaction ID --url string URL of HTTP endpoint to listen on or connect to (default "127.0.0.1:9181") ``` -------------------------------- ### DefraDB CLI: Index Create Command Options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_index_create.md Documentation for the specific command-line options available with `defradb client index create`, detailing their purpose and usage. ```APIDOC -c, --collection string Collection name --fields strings Fields to index -h, --help help for create -n, --name string Index name -u, --unique Make the index unique ``` -------------------------------- ### Basic GraphQL Query Example in DefraDB Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/explain-systems.md This snippet shows a standard GraphQL query to retrieve Author data, including _docID, name, and age, without invoking the Explain System. It represents a typical data retrieval operation. ```graphql query { Author { _docID name age } } ``` -------------------------------- ### Query DefraDB for a Specific Document Commit by CID Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/getting-started.md Demonstrates how to query DefraDB using the `defradb client query` command to retrieve a specific document commit by its content identifier (CID). The query fetches the commit's CID, delta, height, and linked subgraph commits. ```shell defradb client query ' query { commits(cid: "bafybeifhtfs6vgu7cwbhkojneh7gghwwinh5xzmf7nqkqqdebw5rqino7u") { cid delta height links { cid name } } } ' ``` -------------------------------- ### defradb client collection describe command line options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_collection_describe.md Detailed documentation for all command-line options available for `defradb client collection describe`, including specific command options and those inherited from parent commands. Each option includes its type, purpose, and default value where applicable. ```APIDOC Options: --collection-id string Collection P2P identifier --get-inactive Get inactive collections as well as active -h, --help help for describe --name string Collection name --version-id string Collection version ID Options inherited from parent commands: -i, --identity string Hex formatted private key used to authenticate with ACP --keyring-backend string Keyring backend to use. Options are file or system (default "file") --keyring-namespace string Service name to use when using the system backend (default "defradb") --keyring-path string Path to store encrypted keys when using the file backend (default "keys") --log-format string Log format to use. Options are text or json (default "text") --log-level string Log level to use. Options are debug, info, error, fatal (default "info") --log-output string Log output path. Options are stderr or stdout. (default "stderr") --log-overrides string Logger config overrides. Format ,=,...;,... --log-source Include source location in logs --log-stacktrace Include stacktrace in error and fatal logs --no-keyring Disable the keyring and generate ephemeral keys --no-log-color Disable colored log output --rootdir string Directory for persistent data (default: $HOME/.defradb) --secret-file string Path to the file containing secrets (default ".env") --source-hub-address string The SourceHub address authorized by the client to make SourceHub transactions on behalf of the actor --tx uint Transaction ID --url string URL of HTTP endpoint to listen on or connect to (default "127.0.0.1:9181") ``` -------------------------------- ### Key Files for DefraDB Request Entry Points Source: https://github.com/sourcenetwork/defradb/blob/develop/internal/db/data_flow.md Lists the essential Go files responsible for handling different request entry points in DefraDB, such as the main client interface, HTTP handlers, and CLI wrappers. ```APIDOC client/db.go - Main client interface implementation http/handler.go - HTTP request routing and handling http/handler_collection.go - Collection-specific handlers cli/client.go - Command-line interface wrapper cli/collection_*.go - Collection CLI commands ``` -------------------------------- ### Go Benchmark for DefraDB IsDocRegistered Function Source: https://github.com/sourcenetwork/defradb/blob/develop/tests/bench/acp/acp_bench_report_20250120.md This Go benchmark function tests the performance of the `IsDocRegistered` method in the DefraDB Access Control Policy (ACP) module. It iterates through different scales of registered document objects (256 to 8192) and tests both in-memory and persistent ACP configurations. The timer is reset and stopped for setup, then started for the `IsDocRegistered` call. ```go func BenchmarkACPIsDocRegistered(b *testing.B) { for _, inMemoryOrPersistent := range []bool{true, false} { for _, scaleBy := range []int{256, 512, 1024, 2048, 4096, 8192} { b.Run( fmt.Sprintf("scale=%d,inMem=%t", scaleBy, inMemoryOrPersistent), func(b *testing.B) { localACP := newLocalACPSetup(b, inMemoryOrPersistent) defer localACP.Close() b.ResetTimer() for bNIndex := 0; bNIndex < b.N; bNIndex++ { // Since we need to re-initialize for every run use stop-start. b.StopTimer() ctx := context.Background() resetLocalACPKeepPolicy(b, ctx, localACP) registerXDocObjects(b, ctx, scaleBy, localACP) b.StartTimer() _, err := localACP.IsDocRegistered(ctx, validPolicyID, "users", "1") if err != nil { b.Fatal(err) } } }, ) } } } ``` -------------------------------- ### defradb client collection get specific options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_collection_get.md Lists the command-line options directly applicable to the `defradb client collection get` command, including help and the option to show deleted documents. ```APIDOC -h, --help: help for get --show-deleted: Show deleted documents ``` -------------------------------- ### defradb client collection get command syntax overview Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_collection_get.md Provides the general command-line syntax for `defradb client collection get`, showing the required document ID argument and optional flags like identity and show-deleted. ```Shell defradb client collection get [-i --identity] [--show-deleted] [flags] ``` -------------------------------- ### Install gh-md-toc manually on Linux Source: https://github.com/sourcenetwork/defradb/blob/develop/tools/scripts/md-toc/README.md This snippet provides instructions for manually installing gh-md-toc on Linux by downloading the script via wget and making it executable. ```bash $ wget https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc $ chmod a+x gh-md-toc ``` -------------------------------- ### DefraDB CLI: Index Create Command Synopsis Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_index_create.md The complete command-line syntax for `defradb client index create`, detailing required and optional parameters for defining a secondary index. ```CLI defradb client index create -c --collection --fields [-n --name ] [--unique] [flags] ``` -------------------------------- ### DefraDB CLI: Inherited Command Options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_index_create.md Documentation for common command-line options inherited from parent commands, applicable across DefraDB client operations, covering authentication, logging, and data management. ```APIDOC -i, --identity string Hex formatted private key used to authenticate with ACP --keyring-backend string Keyring backend to use. Options are file or system (default "file") --keyring-namespace string Service name to use when using the system backend (default "defradb") --keyring-path string Path to store encrypted keys when using the file backend (default "keys") --log-format string Log format to use. Options are text or json (default "text") --log-level string Log level to use. Options are debug, info, error, fatal (default "info") --log-output string Log output path. Options are stderr or stdout. (default "stderr") --log-overrides string Logger config overrides. Format ,=,...;,... --log-source Include source location in logs --log-stacktrace Include stacktrace in error and fatal logs --no-keyring Disable the keyring and generate ephemeral keys --no-log-color Disable colored log output --rootdir string Directory for persistent data (default: $HOME/.defradb) --secret-file string Path to the file containing secrets (default ".env") --source-hub-address string The SourceHub address authorized by the client to make SourceHub transactions on behalf of the actor --tx uint Transaction ID --url string URL of HTTP endpoint to listen on or connect to (default "127.0.0.1:9181") ``` -------------------------------- ### Install gh-md-toc using Basher on Linux or MacOS Source: https://github.com/sourcenetwork/defradb/blob/develop/tools/scripts/md-toc/README.md This snippet demonstrates how to install gh-md-toc using the Basher package manager, a method applicable to both Linux and MacOS systems. ```bash $ basher install ekalinin/github-markdown-toc ``` -------------------------------- ### Install gh-md-toc manually on MacOS Source: https://github.com/sourcenetwork/defradb/blob/develop/tools/scripts/md-toc/README.md This snippet outlines the manual installation process for gh-md-toc on MacOS, involving downloading the script using curl and then setting its executable permissions. ```bash $ curl https://raw.githubusercontent.com/ekalinin/github-markdown-toc/master/gh-md-toc -o gh-md-toc $ chmod a+x gh-md-toc ``` -------------------------------- ### CLI Options for defradb client backup Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_backup.md Standard command-line options specific to the `defradb client backup` command, providing help information. ```CLI -h, --help help for backup ``` -------------------------------- ### Starting DefraDB with CORS Enabled Source: https://github.com/sourcenetwork/defradb/blob/develop/playground/README.md Starts the DefraDB backend server, configuring it to allow cross-origin requests from all origins. This is essential for local development when the playground is served from a different origin. ```bash defradb start --allowed-origins="*" ``` -------------------------------- ### Execute Go BenchmarkACPRegister for document registration Source: https://github.com/sourcenetwork/defradb/blob/develop/tests/bench/acp/acp_bench_report_20250120.md Provides the shell command to run the `BenchmarkACPRegister` Go benchmark. It uses `humanbench` for readable output, sets the log level to error, and includes memory allocation statistics, with each benchmark run limited to 1 second. ```Shell LOG_LEVEL=error humanbench go test -bench=. -benchmem -benchtime 1s ``` -------------------------------- ### Start DefraDB Node Without P2P Networking Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/guides/peer-to-peer.md Starts a DefraDB node with the peer-to-peer networking stack explicitly disabled. This prevents the node from participating in the P2P network. ```bash $ defradb start --no-p2p ``` -------------------------------- ### defradb client index command options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_index.md Lists the command-specific options available for the `defradb client index` command, including help. ```CLI -h, --help help for index ``` -------------------------------- ### defradb client p2p collection Command-Specific Options Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_p2p_collection.md Lists the command-line options directly available for the `defradb client p2p collection` command, including the help flag. ```Shell -h, --help help for collection ``` -------------------------------- ### defradb client dump Command Usage Source: https://github.com/sourcenetwork/defradb/blob/develop/docs/website/references/cli/defradb_client_dump.md Shows the basic command-line syntax for using `defradb client dump` with its general flag placeholder. ```CLI defradb client dump [flags] ```