npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

salesforce-to-sqlite

v1.0.2

Published

CLI tool to extract Salesforce data and load into SQLite

Readme

Salesforce to SQLite CLI Tool

A Node.js CLI tool that extracts data from Salesforce and loads it into a SQLite database based on a load plan configuration.

Features

  • Extracts data from Salesforce using SF CLI
  • Creates SQLite tables automatically based on query results
  • Handles Salesforce relationship fields (e.g., Parent.Name becomes Parent_Name in SQLite)
  • Automatic data type inference
  • Progress logging with colored output
  • Verbose mode for debugging

Prerequisites

  • Node.js (v14 or higher)
  • Salesforce CLI (sf) installed and authenticated
  • Active Salesforce org connection

Sample Load Plans

SQLite Explorer Pro

Use this explorer to explore the create database:

Installation

npm install -g salesforce-to-sqlite

Usage

Basic Usage

sf2sqlite  -o <salesforce-username> -l load-plan.json

With Custom Database Name

sf2sqlite  -o [email protected] -l load-plan.json -d my-data.db

Verbose Mode

sf2sqlite  -o [email protected] -l load-plan.json -v

Options

  • -o, --org <username> - Salesforce org username or alias (required)
  • -l, --load-plan <file> - Path to load plan JSON file (required)
  • -d, --database <file> - SQLite database file path (default: salesforce.db)
  • -v, --verbose - Enable verbose logging
  • -h, --help - Display help information
  • -V, --version - Display version number

Load Plan Format

The load plan is a JSON array of object configurations. Each configuration includes:

{
  "object": "ObjectName",
  "compositeKeys": ["Field1", "Field2"],
  "query": "SELECT Field1, Field2, Related.Field FROM ObjectName",
  "fieldMappings": {
    "Field1": "Field1",
    "Field2": {
      "lookup": {
        "object": "RelatedObject",
        "key": "KeyField",
        "field": "Related.Field"
      }
    }
  }
}

How It Works

  1. Read Load Plan: Parses the JSON configuration file
  2. Query Salesforce: Executes each SOQL query using sf data query
  3. Field Name Sanitization: Converts relationship fields (e.g., Account.Name) to SQLite-compatible names (Account_Name)
  4. Table Creation: Creates SQLite tables with inferred data types
  5. Data Insertion: Inserts queried data into SQLite tables
  6. Type Conversion: Automatically converts Salesforce data types to SQLite equivalents

Field Name Handling

Salesforce relationship fields like Parent.Name or Account.Owner.Email are automatically converted to SQLite-compatible field names:

  • Parent.NameParent_Name
  • Account.Owner.EmailAccount_Owner_Email
  • Product2.StockKeepingUnitProduct2_StockKeepingUnit

Data Type Mapping

| Salesforce Type | SQLite Type | Notes | |----------------|-------------|-------| | String/Text | TEXT | Default for most fields | | Boolean | INTEGER | true=1, false=0 | | Number (Integer) | INTEGER | Whole numbers | | Number (Decimal) | REAL | Decimal numbers | | Date/DateTime | TEXT | ISO format strings | | ID | TEXT | Salesforce IDs |

Examples

Extract Product Catalog Data

sf2sqlite  -o production-org -l load-plan.json -d catalog.db

Debug Query Issues

sf2sqlite  -o sandbox -l load-plan.json -v

Output

The tool provides colored console output:

  • 🔵 Info messages
  • ✅ Success messages
  • ⚠️ Warning messages
  • ❌ Error messages

At the end, a summary shows:

  • Number of successfully processed objects
  • Number of failed objects
  • Location of the SQLite database file

Error Handling

  • Invalid load plan JSON: Exits with error message
  • Failed Salesforce queries: Logs warning and continues with next object
  • Table creation errors: Logs error and skips object
  • Record insertion errors: Logs error but continues with other records

Performance Notes

  • Large queries use a 50MB buffer for CSV data
  • SQLite WAL mode is enabled for better performance
  • Batch inserts using transactions for speed
  • Progress is logged for each object

Troubleshooting

"Command not found: sf"

Install Salesforce CLI: https://developer.salesforce.com/tools/salesforcecli

"No auth found for org"

Authenticate with: sf org login web -a <alias>

"Query timeout"

Try splitting large objects into smaller queries or increase the buffer size in the code

"Failed to parse CSV"

Check query syntax and ensure fields exist in your org

License

MIT (c) Mohan Chinnappan