### Build Neon CLI Locally Source: https://github.com/neondatabase/neonctl/blob/main/README.md Commands to set up and build the Neon CLI locally. 'bun install' installs dependencies, and 'bun run build' compiles the project. ```shell bun install bun run build ``` -------------------------------- ### Manage Neon Projects Source: https://github.com/neondatabase/neonctl/blob/main/README.md Demonstrates commands for managing Neon projects, including listing, creating, updating, deleting, and getting project details. ```bash neonctl projects list ``` ```bash neonctl projects create ``` ```bash neonctl projects update ``` ```bash neonctl projects delete ``` ```bash neonctl projects get ``` -------------------------------- ### Create Branch (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Provides examples for creating a new database branch within a Neon project using neonctl. Covers basic branch creation from the default parent and optionally specifying compute resources. ```bash # Create basic branch from default parent neonctl branches create --name feature-1 --project-id my-project-id ``` -------------------------------- ### List Branches (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Demonstrates how to list all database branches within a Neon project using neonctl. Shows examples for project-specific listing and JSON output, noting how default and protected branches are indicated. ```bash # List branches for a project neonctl branches list --project-id my-project-id # List with JSON output neonctl branches list --project-id my-project-id --output json # Default branches are marked with ✱ # Protected branches are marked with ⛨ ``` -------------------------------- ### API Key Authentication (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Shows how to authenticate using API keys for automation and CI/CD. Includes examples for listing projects with an API key, setting the key via environment variable, and using it in scripts for operations like creating branches. ```bash # List projects using API key neonctl projects list --api-key neon_api_abc123xyz # Set API key via environment variable export NEON_API_KEY=neon_api_abc123xyz neonctl projects list # Use in scripts neonctl branches create --name feature-branch --project-id my-project --api-key $NEON_API_KEY ``` -------------------------------- ### Install Neon CLI with Homebrew Source: https://github.com/neondatabase/neonctl/blob/main/README.md Installs the Neon CLI using the Homebrew package manager. ```shell brew install neonctl ``` -------------------------------- ### Install Neon CLI with npm Source: https://github.com/neondatabase/neonctl/blob/main/README.md Installs the Neon CLI globally using npm. Requires Node.js 18.0 or higher. ```shell npm i -g neonctl ``` -------------------------------- ### Get Project Details (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Shows how to retrieve detailed information about a specific Neon project using its ID with neonctl. Supports outputting details in JSON format. ```bash # Get project by ID neonctl projects get my-project-id # Get project with JSON output neonctl projects get my-project-id --output json ``` -------------------------------- ### Update Project (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Illustrates how to update existing Neon project settings using neonctl. Examples include changing the project name, adjusting compute units, blocking public connections, and enabling HIPAA compliance. ```bash # Update project name neonctl projects update my-project-id --name new-project-name # Update compute units neonctl projects update my-project-id --cu 1-3 # Block public connections neonctl projects update my-project-id --block-public-connections # Enable HIPAA compliance neonctl projects update my-project-id --hipaa ``` -------------------------------- ### Get Neon Connection String Source: https://github.com/neondatabase/neonctl/blob/main/README.md Retrieves the connection string for Neon. ```bash neonctl connection-string ``` -------------------------------- ### Display Neon CLI Help Source: https://github.com/neondatabase/neonctl/blob/main/README.md Displays help information for the Neon CLI. This can be used to get general help, or specific help for commands and subcommands. ```bash neonctl --help neonctl branches --help neonctl branches create --help ``` -------------------------------- ### Token Refresh (TypeScript) Source: https://context7.com/neondatabase/neonctl/llms.txt Provides a TypeScript example for refreshing expired access tokens using a stored refresh token. It takes existing token set details and returns a new set of tokens. Requires the 'refreshToken' function. ```typescript import { refreshToken } from './auth.js'; const newTokenSet = await refreshToken( { oauthHost: 'https://oauth2.neon.tech', clientId: 'neonctl', allowUnsafeTls: false }, existingTokenSet ); console.log('New Access Token:', newTokenSet.access_token); ``` -------------------------------- ### Create Project (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Shows various ways to create a new Neon project using neonctl. Covers basic creation, specifying region, custom compute units, database names, roles, direct psql connection, HIPAA compliance, and setting the project as the current context. ```bash # Basic project creation neonctl projects create --name my-app-db # Create with specific region neonctl projects create --name my-app-db --region-id aws-us-east-1 # Create with custom compute units and database settings neonctl projects create \ --name my-app-db \ --region-id aws-eu-central-1 \ --cu 2-4 \ --database mydb \ --role myuser # Create and immediately connect via psql neonctl projects create --name my-app-db --psql # Create with HIPAA compliance neonctl projects create --name healthcare-db --hipaa # Create and set as current context neonctl projects create --name my-app-db --set-context ``` -------------------------------- ### Initialize Neon API Client and Manage Resources in TypeScript Source: https://context7.com/neondatabase/neonctl/llms.txt Demonstrates how to initialize the Neon API client using an API key and host, and perform common operations like listing projects, retrieving project details, and creating branches. It also shows how to use a `retryOnLock` utility for handling resource lock errors during updates or deletions. ```typescript import { getApiClient } from './api.js'; // Create client with API key const apiClient = getApiClient({ apiKey: 'neon_api_abc123xyz', apiHost: 'https://console.neon.tech/api/v2' }); // List projects const { data } = await apiClient.listProjects({ limit: 100 }); console.log('Projects:', data.projects); // Get project details const projectData = await apiClient.getProject('my-project-id'); console.log('Project:', projectData.data.project); // Create branch const branchData = await apiClient.createProjectBranch('my-project-id', { branch: { name: 'feature-branch' }, endpoints: [{ type: 'read_write' }] }); console.log('Branch:', branchData.data.branch); import { retryOnLock } from './api.js'; // Automatically retries up to 5 times on 423 Locked responses const result = await retryOnLock(async () => { return await apiClient.updateProjectBranch( 'my-project-id', 'branch-id', { branch: { name: 'new-name' } } ); }); console.log('Updated branch:', result.data.branch); // Useful for operations that may conflict with background processes const deleteResult = await retryOnLock(() => apiClient.deleteProjectBranchDatabase( 'my-project-id', 'branch-id', 'database-name' ) ); ``` -------------------------------- ### Configure neonctl and Access Help Information Source: https://context7.com/neondatabase/neonctl/llms.txt Instructions on how to specify a custom configuration directory for neonctl and how to access version information and help documentation for the CLI and its commands. Includes generating shell completion scripts. ```bash # Use custom config directory neonctl projects list --config-dir /custom/path/.neonctl # Default location: ~/.config/neonctl # Contains credentials.json and context.json files # Show version neonctl --version neonctl -v # Show general help neonctl --help # Show command-specific help neonctl projects --help neonctl branches create --help # Generate shell completion script neonctl completion ``` -------------------------------- ### Manage neonctl Context Settings Source: https://context7.com/neondatabase/neonctl/llms.txt Commands to configure the default project, branch, or organization for the current session using `neonctl set-context`. It also shows how to clear the context to reset to defaults and how to view the current context configuration file. ```bash # Set default project neonctl set-context --project-id my-project-id # Set default branch neonctl set-context --project-id my-project-id --branch main # Set default organization neonctl set-context --org-id org-123456 # Clear context (reset to defaults) neonctl set-context # View current context cat ~/.config/neonctl/context.json ``` -------------------------------- ### List Projects (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Demonstrates how to list Neon projects using the neonctl CLI. Supports various output formats (table, JSON) and filtering options like organization ID and recoverable projects. ```bash # List all projects in table format neonctl projects list # List projects in JSON format neonctl projects list --output json # List projects for a specific organization neonctl projects list --org-id org-123456 # List only recoverable (deleted) projects neonctl projects list --recoverable-only ``` -------------------------------- ### Delete and Recover Projects (Bash) Source: https://context7.com/neondatabase/neonctl/llms.txt Explains how to delete Neon projects and recover them if they are still within the deletion grace period using neonctl. Includes commands for deleting, listing recoverable projects, and recovering a deleted project. ```bash # Delete a project neonctl projects delete my-project-id # View recoverable projects neonctl projects list --recoverable-only # Recover a deleted project neonctl projects recover my-project-id ``` -------------------------------- ### List Neon Databases with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Display all databases within a Neon branch, either the default branch or a specified branch. Supports JSON output format. Requires a project ID. ```bash neonctl databases list --project-id my-project-id neonctl databases list --project-id my-project-id --branch feature-1 neonctl databases list --project-id my-project-id --output json ``` -------------------------------- ### Create Neon Database with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Create a new database within a Neon branch, with options to auto-detect owner or specify a role, and target a specific branch. Requires a project ID. ```bash neonctl databases create --name myapp --project-id my-project-id neonctl databases create --name myapp --owner-name admin --project-id my-project-id neonctl databases create --name myapp --project-id my-project-id --branch feature-1 ``` -------------------------------- ### OAuth Authentication Flow (TypeScript) Source: https://context7.com/neondatabase/neonctl/llms.txt Demonstrates the OAuth-based authentication flow using OpenID Connect with PKCE. It securely authorizes users and retrieves access and refresh tokens. Requires the 'auth' module and default client ID. ```typescript import { auth, defaultClientID } from './auth.js'; // Authenticate with default settings const tokenSet = await auth({ oauthHost: 'https://oauth2.neon.tech', clientId: defaultClientID, allowUnsafeTls: false }); // Access tokens from the response console.log('Access Token:', tokenSet.access_token); console.log('Refresh Token:', tokenSet.refresh_token); console.log('Expires In:', tokenSet.expires_in); // Token will automatically open browser for user authentication // Server listens on localhost:random-port for OAuth callback ``` -------------------------------- ### List Neon Roles with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Display all roles (database users) within a Neon branch, either the default branch or a specified branch. Supports JSON output format. Requires a project ID. ```bash neonctl roles list --project-id my-project-id neonctl roles list --project-id my-project-id --branch feature-1 neonctl roles list --project-id my-project-id --output json ``` -------------------------------- ### Create Neon Branches with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Create new Neon branches with various configurations, including from a parent branch, specific timestamp, LSN, with or without compute, custom compute units, read-only, schema-only, with expiration, or for direct psql connection. Requires a project ID. ```bash neonctl branches create --name feature-2 --parent main --project-id my-project-id neonctl branches create --name feature-3 --parent 2024-01-15T10:30:00Z --project-id my-project-id neonctl branches create --name feature-4 --parent 0/1A2B3C4D --project-id my-project-id neonctl branches create --name data-branch --no-compute --project-id my-project-id neonctl branches create --name feature-5 --cu 1-2 --project-id my-project-id neonctl branches create --name readonly-1 --type read_only --project-id my-project-id neonctl branches create --name schema-only --schema-only --project-id my-project-id neonctl branches create --name temp-branch --expires-at 2024-12-31T23:59:59Z --project-id my-project-id neonctl branches create --name feature-6 --psql --project-id my-project-id ``` -------------------------------- ### Generate PostgreSQL Connection Strings with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Generates various PostgreSQL connection strings for different configurations, including default, specific branches, pooled connections, Prisma optimization, role and database specification, read-only endpoints, extended details, and direct psql connections. Supports point-in-time and custom SSL modes. ```bash # Get connection string for default branch neonctl connection-string --project-id my-project-id # Get for specific branch neonctl connection-string main --project-id my-project-id # Get pooled connection neonctl connection-string main --pooled --project-id my-project-id # Get Prisma-optimized connection string neonctl connection-string main --prisma --pooled --project-id my-project-id # Get with specific role and database neonctl connection-string main --role-name admin --database-name mydb --project-id my-project-id # Get for read-only endpoint neonctl connection-string main --endpoint-type read_only --project-id my-project-id # Get with extended details neonctl connection-string main --extended --project-id my-project-id # Connect immediately via psql neonctl connection-string main --psql --project-id my-project-id # Pass additional psql arguments neonctl connection-string main --psql --project-id my-project-id -- -c "SELECT version();" # Point-in-time connection strings neonctl connection-string main@2024-01-01T00:00:00Z --project-id my-project-id neonctl connection-string main@0/234235 --project-id my-project-id # Custom SSL modes neonctl connection-string main --ssl verify-full --project-id my-project-id neonctl connection-string main --ssl omit --project-id my-project-id ``` -------------------------------- ### Manage Neon Databases Source: https://github.com/neondatabase/neonctl/blob/main/README.md Commands for managing databases within Neon, including listing, creating, and deleting them. ```bash neonctl databases list ``` ```bash neonctl databases create ``` ```bash neonctl databases delete ``` -------------------------------- ### Authenticate Neon CLI Source: https://github.com/neondatabase/neonctl/blob/main/README.md Authenticates a connection to Neon by launching a browser window for authorization. Alternatively, an API key can be used. ```bash neonctl auth ``` ```bash neonctl projects list --api-key ``` -------------------------------- ### Create and Delete Neon Roles with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Commands to create new roles with or without login capabilities, and to delete existing roles. Roles can be created or deleted for the entire project or specific branches. Requires project ID and optionally a branch name. ```bash # Create standard role with login neonctl roles create --name developer --project-id my-project-id # Create passwordless role without login capability neonctl roles create --name app_role --no-login --project-id my-project-id # Create in specific branch neonctl roles create --name analyst --project-id my-project-id --branch feature-1 # Delete role neonctl roles delete developer --project-id my-project-id # Delete from specific branch neonctl roles delete analyst --project-id my-project-id --branch feature-1 ``` -------------------------------- ### Run Local Neon CLI Build Source: https://github.com/neondatabase/neonctl/blob/main/README.md Executes commands from a locally built Neon CLI. Replace 'neonctl' with 'node dist' to run the local version. ```shell node dist branches --help ``` -------------------------------- ### Compare Neon Branch Schemas with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Perform schema difference comparisons between Neon branches or historical points in time (timestamp, LSN, parent). Can specify a particular database for comparison. Requires a project ID. ```bash neonctl branches schema-diff my-branch --project-id my-project-id neonctl branches schema-diff main feature-branch --project-id my-project-id neonctl branches schema-diff main compare@2024-06-01T00:00:00Z --project-id my-project-id neonctl branches schema-diff my-branch ^self@0/123456 --project-id my-project-id neonctl branches schema-diff my-branch ^parent --database mydb --project-id my-project-id ``` -------------------------------- ### Add Compute to Neon Branches with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Add compute endpoints to existing Neon branches, with options for default read-only, read-write, custom compute units, and custom compute names. Requires a project ID. ```bash neonctl branches add-compute my-branch --project-id my-project-id neonctl branches add-compute my-branch --type read_write --project-id my-project-id neonctl branches add-compute my-branch --cu 2-4 --project-id my-project-id neonctl branches add-compute my-branch --name my-compute --project-id my-project-id ``` -------------------------------- ### Manage Neon Roles Source: https://github.com/neondatabase/neonctl/blob/main/README.md Commands for managing roles in Neon, including listing, creating, and deleting them. ```bash neonctl roles list ``` ```bash neonctl roles create ``` ```bash neonctl roles delete ``` -------------------------------- ### Specify Neon CLI Configuration Directory Source: https://github.com/neondatabase/neonctl/blob/main/README.md Specifies a custom path to the Neon CLI configuration directory. This is typically needed only if the configuration files, such as 'credentials.json', are not in the default location. The default location is usually '/home//.config/neonctl'. ```bash neonctl projects list --config-dir /home/dtprice/.config/neonctl ``` -------------------------------- ### Manage Neon IP Allow Source: https://github.com/neondatabase/neonctl/blob/main/README.md Commands for managing IP allow rules for Neon, including listing, adding, removing, and resetting rules. ```bash neonctl ip-allow list ``` ```bash neonctl ip-allow add ``` ```bash neonctl ip-allow remove ``` ```bash neonctl ip-allow reset ``` -------------------------------- ### Show Current Neon User Source: https://github.com/neondatabase/neonctl/blob/main/README.md Displays information about the currently authenticated user in Neon. ```bash neonctl me ``` -------------------------------- ### Control neonctl Output Formatting Source: https://context7.com/neondatabase/neonctl/llms.txt Options to control the output format of neonctl commands, including table (default), JSON, YAML, and disabling colors. Also covers enabling/disabling analytics tracking. ```bash # Table format (default) neonctl projects list # JSON format neonctl projects list --output json # YAML format neonctl projects list --output yaml # Disable colors neonctl projects list --no-color # Enable analytics (default) neonctl projects list --analytics # Disable analytics neonctl projects list --no-analytics ``` -------------------------------- ### Manage Neon Branches Source: https://github.com/neondatabase/neonctl/blob/main/README.md Commands for managing Neon branches, including listing, creating, renaming, adding compute, setting default and expiration, and deleting branches. ```bash neonctl branches list ``` ```bash neonctl branches create ``` ```bash neonctl branches rename ``` ```bash neonctl branches add-compute ``` ```bash neonctl branches set-default ``` ```bash neonctl branches set-expiration ``` ```bash neonctl branches delete ``` ```bash neonctl branches get ``` -------------------------------- ### Display Neon CLI Version Source: https://github.com/neondatabase/neonctl/blob/main/README.md Shows the current version number of the Neon CLI. ```bash neonctl --version 1.15.0 ``` -------------------------------- ### Authenticate with Neon API Key Source: https://github.com/neondatabase/neonctl/blob/main/README.md Allows authentication with Neon CLI commands using a Neon API key directly, bypassing the need for 'neonctl auth'. Obtain your API key from the Neon API Reference. ```bash neonctl --api-key ``` -------------------------------- ### Manage Neon Branches with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Perform common branch operations like renaming, setting default, deleting, resetting, and restoring branches to specific states (parent, timestamp, LSN). Also includes setting or removing branch expiration. Requires a project ID. ```bash neonctl branches rename old-name new-name --project-id my-project-id neonctl branches set-default main --project-id my-project-id neonctl branches delete feature-branch --project-id my-project-id neonctl branches reset my-branch --parent --project-id my-project-id neonctl branches reset my-branch --parent --preserve-under-name backup-branch --project-id my-project-id neonctl branches restore main br-source-branch-123456 --project-id my-project-id neonctl branches restore main source@2024-01-01T00:00:00Z --project-id my-project-id neonctl branches restore my-branch ^self@0/123456 --project-id my-project-id neonctl branches restore my-branch ^parent --project-id my-project-id neonctl branches set-expiration my-branch --expires-at 2024-12-31T23:59:59Z --project-id my-project-id neonctl branches set-expiration my-branch --project-id my-project-id ``` -------------------------------- ### Set Neon CLI Output Format Source: https://github.com/neondatabase/neonctl/blob/main/README.md Sets the output format for Neon CLI commands. Supported formats include 'json', 'yaml', and 'table'. 'table' is the default, while 'json' and 'yaml' provide more comprehensive data. Table output may have limitations. ```bash neonctl me --output json ``` -------------------------------- ### Upgrade Neon CLI with Homebrew Source: https://github.com/neondatabase/neonctl/blob/main/README.md Upgrades the Neon CLI using the Homebrew package manager. ```shell brew upgrade neonctl ``` -------------------------------- ### Generate Neon CLI Autocompletion Source: https://github.com/neondatabase/neonctl/blob/main/README.md Generates a completion script for Neon CLI autocompletion. ```bash neonctl completion ``` -------------------------------- ### Watch for Changes in Neon CLI Build Source: https://github.com/neondatabase/neonctl/blob/main/README.md Continuously builds the Neon CLI project as changes are detected, useful for active development. ```shell bun run watch ``` -------------------------------- ### Manage Neon Operations Source: https://github.com/neondatabase/neonctl/blob/main/README.md Command to list ongoing operations within Neon. ```bash neonctl operations list ``` -------------------------------- ### Delete Neon Database with neonctl Source: https://context7.com/neondatabase/neonctl/llms.txt Remove a database from a Neon branch, with the option to specify the target branch. Requires a project ID. ```bash neonctl databases delete myapp --project-id my-project-id neonctl databases delete myapp --project-id my-project-id --branch feature-1 ``` -------------------------------- ### Upgrade Neon CLI with npm Source: https://github.com/neondatabase/neonctl/blob/main/README.md Upgrades the Neon CLI globally using npm. Requires Node.js 18.0 or higher. ```shell npm update -g neonctl ``` -------------------------------- ### Set Neon Context Source: https://github.com/neondatabase/neonctl/blob/main/README.md Sets the context for the current Neon CLI session. ```bash neonctl set-context ``` -------------------------------- ### Manage Neon CLI Analytics Source: https://github.com/neondatabase/neonctl/blob/main/README.md Controls the collection of analytics data for CLI commands and options used by customers. This data helps improve user experience and support. To opt-out, use '--no-analytics' or '--analytics false'. Data collection does not include user-defined information like project IDs or command payloads. === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.