Sign inSign up

toolkitbox/sqlite

By toolkitbox

Updated 23 days ago

DevOps toolkit - sqlite client

Image
0

1.1K

toolkitbox/sqlite repository overview

SQLite3 Client

GitHub Stars GitHub Issues Docker Pulls

📢 Found an issue or want to request a new tool? Open an issue on GitHub

Command line interface for SQLite3.

Quick Start

Docker
# Interactive mode with a database file
docker run -it --rm \
  -v $(pwd):/data \
  ghcr.io/pabpereza/toolkitbox/sqlite:latest \
  sqlite3 /data/mydatabase.db

# Execute single query
docker run --rm \
  -v $(pwd):/data \
  ghcr.io/pabpereza/toolkitbox/sqlite:latest \
  sqlite3 /data/mydatabase.db "SELECT * FROM users;"

# Create in-memory database for testing
docker run -it --rm \
  ghcr.io/pabpereza/toolkitbox/sqlite:latest \
  sqlite3 :memory:
Kubernetes
apiVersion: v1
kind: Pod
metadata:
  name: sqlite-client
spec:
  containers:
  - name: sqlite-client
    image: ghcr.io/pabpereza/toolkitbox/sqlite:latest
    command: ["sleep", "infinity"]
    volumeMounts:
    - name: data
      mountPath: /data
  volumes:
  - name: data
    persistentVolumeClaim:
      claimName: sqlite-data

Description

SQLite3 (sqlite3) is the official command line interface for interacting with SQLite databases. It allows you to create, query, and manage SQLite database files, execute SQL commands, and perform data import/export operations.

Installation

This component installs sqlite from the Alpine Linux repositories.

Basic Usage

Open or create a database
sqlite3 mydatabase.db
Open database in read-only mode
sqlite3 -readonly mydatabase.db
Execute command and exit
sqlite3 mydatabase.db "SELECT * FROM users;"
Execute SQL from file
sqlite3 mydatabase.db < script.sql
Use in-memory database
sqlite3 :memory:

Useful Commands

Table operations
-- Create table
CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT UNIQUE
);

-- Insert data
INSERT INTO users (name, email) VALUES ('John', '[email protected]');

-- Select data
SELECT * FROM users;

-- Update data
UPDATE users SET name = 'Jane' WHERE id = 1;

-- Delete data
DELETE FROM users WHERE id = 1;
Schema inspection
-- Show all tables
.tables

-- Show table schema
.schema users

-- Describe table structure
PRAGMA table_info(users);

-- Show all indexes
.indexes
Data import/export
# Export to CSV
sqlite3 -header -csv mydatabase.db "SELECT * FROM users;" > users.csv

# Import from CSV
sqlite3 mydatabase.db
.mode csv
.import users.csv users

# Dump database to SQL
sqlite3 mydatabase.db .dump > backup.sql

# Restore from SQL dump
sqlite3 newdatabase.db < backup.sql

Common Options

OptionDescription
-headerShow column headers
-csvOutput in CSV format
-jsonOutput in JSON format
-lineOutput one value per line
-columnOutput in column format
-readonlyOpen database in read-only mode
-cmdRun command before reading stdin
-initRead and execute commands from file

Dot Commands

# Show help
.help

# Show tables
.tables

# Show schema
.schema

# Change output mode
.mode csv
.mode json
.mode column
.mode line

# Enable headers
.headers on

# Open another database
.open another.db

# Attach database
ATTACH DATABASE 'other.db' AS other;

# Show current settings
.show

# Exit
.exit

Output Modes

# CSV format
.mode csv
SELECT * FROM users;

# JSON format
.mode json
SELECT * FROM users;

# Column format (pretty table)
.mode column
.headers on
SELECT * FROM users;

# Line format (one value per line)
.mode line
SELECT * FROM users;

Official Documentation

Tag summary

Content type

Image

Digest

sha256:1326b96a8

Size

8.1 MB

Last updated

23 days ago

docker pull toolkitbox/sqlite