### Install and Load sqlite-path in Python
Source: https://context7.com/asg017/sqlite-path/llms.txt
Demonstrates how to install the sqlite-path extension using pip and load it into a Python SQLite database connection. It then verifies the installation by querying the extension's version.
```python
import sqlite3
import sqlite_path
# Connect to SQLite and enable extension loading
db = sqlite3.connect(':memory:')
db.enable_load_extension(True)
# Load the extension
sqlite_path.load(db)
# Verify installation
version = db.execute('select path_version()').fetchone()[0]
print(version) # Output: v0.2.1
```
--------------------------------
### Install and Load sqlite-path in Node.js (better-sqlite3)
Source: https://context7.com/asg017/sqlite-path/llms.txt
Shows how to install the sqlite-path extension via npm and load it into a Node.js application using the 'better-sqlite3' library. It verifies the installation by fetching the extension's version.
```javascript
// Install via npm
// npm install sqlite-path
import Database from "better-sqlite3";
import { getLoadablePath } from "sqlite-path";
const db = new Database(":memory:");
db.loadExtension(getLoadablePath());
const version = db.prepare("select path_version() as version").pluck().get();
console.log(version); // Output: v0.2.1
```
--------------------------------
### Install and Load sqlite-path in Deno
Source: https://context7.com/asg017/sqlite-path/llms.txt
Provides instructions for installing and loading the sqlite-path extension within a Deno environment using the 'deno.land/x/sqlite_path' module and 'deno.land/x/sqlite3' for database interaction. It confirms the installation by querying the version.
```typescript
import * as sqlite_path from "https://deno.land/x/sqlite_path/mod.ts";
import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts";
const db = new Database(":memory:");
db.enableLoadExtension = true;
sqlite_path.load(db);
const [version] = db.prepare("select path_version() as version").value<[string]>()!;
console.log(version); // Output: v0.2.1
db.close();
```
--------------------------------
### Get Loadable Path for better-sqlite3
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Provides an example of using the getLoadablePath() function to obtain the path for loading the sqlite-path extension with better-sqlite3. This snippet is a direct usage example from the API documentation.
```javascript
import Database from "better-sqlite3";
import * as sqlite_path from "sqlite-path";
const db = new Database(":memory:");
db.loadExtension(sqlite_path.getLoadablePath());
```
--------------------------------
### Get Loadable Path for node-sqlite3
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Demonstrates using the getLoadablePath() function to get the path for loading the sqlite-path extension with node-sqlite3. This example mirrors the usage shown in the package's API reference.
```javascript
import sqlite3 from "sqlite3";
import * as sqlite_path from "sqlite-path";
const db = new sqlite3.Database(":memory:");
db.loadExtension(sqlite_path.getLoadablePath());
```
--------------------------------
### Install sqlite-path with Package Managers
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Instructions for installing the sqlite-path library using common package managers for different programming languages. This ensures the library is available for use in your projects.
```shell
pip install sqlite-path
```
```shell
datasette install datasette-sqlite-path
```
```shell
npm install sqlite-path
```
```shell
gem install sqlite-path
```
--------------------------------
### Path Version API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Retrieves the semantic version string of the current sqlite-path installation.
```APIDOC
## GET /path_version
### Description
Returns the semver version string of the current version of sqlite-path.
### Method
GET
### Endpoint
/path_version
### Parameters
None
### Request Example
```sql
select path_version();
```
### Response
#### Success Response (200)
- **version** (string) - The semver version string.
#### Response Example
```json
{
"version": "v0.0.0"
}
```
```
--------------------------------
### Get Loadable Path and Load Extension in Python
Source: https://github.com/asg017/sqlite-path/blob/main/python/sqlite_path/README.md
Demonstrates how to use the sqlite-path Python package to get the path to the loadable extension and load it into a sqlite3 connection. It shows how to verify the extension is loaded by querying its version.
```python
import sqlite_path
print(sqlite_path.loadable_path())
# '/.../venv/lib/python3.9/site-packages/sqlite_path/path0'
import sqlite3
conn = sqlite3.connect(':memory:')
sqlite_path.load(conn)
conn.execute('select path_version()').fetchone()
# ('v0.1.0')
```
--------------------------------
### Install datasette-sqlite-path Plugin
Source: https://github.com/asg017/sqlite-path/blob/main/python/datasette_sqlite_path/README.md
Installs the datasette-sqlite-path plugin using the datasette CLI. This makes the sqlite-path extension available within your Datasette instance.
```bash
datasette install datasette-sqlite-path
```
--------------------------------
### Initialize and Query SQL.js with Path Functions (JavaScript)
Source: https://github.com/asg017/sqlite-path/blob/main/tests/test-sqljs.html
Initializes SQL.js with a custom configuration to locate the WASM file and then executes several queries to demonstrate path-related functions and modules. It dynamically generates HTML to display the query results, including function lists, version information, and path component breakdowns. Errors during query execution are caught and reported.
```javascript
import { html } from "https://cdn.skypack.dev/htl";
const config = {
locateFile: (filename, prefix) => {
return `../dist/${filename}`;
},
};
initSqlJs(config).then(function (SQL) {
var db = new SQL.Database();
function printResults(query) {
let stmt = db.prepare(query);
const columns = stmt.getColumnNames();
const rows = [];
while (stmt.step()) {
rows.push(stmt.get());
}
document.body.appendChild(html`
${query}
${columns.map((column) => html`| ${column} | `)}
${rows.map(
(values) => html` ${values.map((d) => html`${d} | `)}
`
)}
`);
}
try {
printResults(`select name from pragma_function_list where name like 'path%'`);
printResults(`select name from pragma_module_list where name like 'path%'`);
printResults("select path_version(), path_debug()");
printResults(`select rowid, type, part from path_parts('/usr/lib/ayoo')`);
document.querySelector("#results").innerText = "✅ tests passed";
} catch {
document.querySelector("#results").innerText = "❌ test(s) failed, check console";
}
});
```
--------------------------------
### Install sqlite-path NPM Package
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Installs the sqlite-path package using npm. This command is used by Node.js developers to add the package to their project dependencies.
```bash
npm install sqlite-path
```
--------------------------------
### Get Loadable Extension Path in Python
Source: https://github.com/asg017/sqlite-path/blob/main/python/sqlite_path/README.md
Retrieves the full path to the locally installed sqlite-path extension without the file extension. This path can be used with sqlite3.Connection.load_extension(), though sqlite_path.load() is the preferred method.
```python
import sqlite_path
print(sqlite_path.loadable_path())
# '/.../venv/lib/python3.9/site-packages/sqlite_path/path0'
```
--------------------------------
### Load sqlite-path as a Runtime Extension with Datasette
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Provides the command to load the sqlite-path extension when starting a Datasette instance. This makes the extension's functions available for querying data served by Datasette.
```shell
datasette data.db --load-extension ./path0
```
--------------------------------
### Querying Deepest .c Files in ZIP Archive with SQL
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Illustrates how to query files within a ZIP archive using SQLite's ZIP support and `sqlite-path` functions. This example finds the top 5 deepest `.c` source code files under the `ext/` directory.
```sql
select
name,
path_length(name) as depth
from zipfile('sqlite.archive.master.zip')
where
-- under the ext/ directory
path_part_at(name, 1) == 'ext'
-- ends in ".c"
and path_extension(name) == '.c'
order by 2 desc
limit 5;
/*
┌────────────────────────────────────────────┬───────┐
│ name │ depth │
├────────────────────────────────────────────┼───────┤
│ sqlite-master/ext/fts3/tool/fts3view.c │ 5 │
│ sqlite-master/ext/lsm1/lsm-test/lsmtest1.c │ 5 │
│ sqlite-master/ext/lsm1/lsm-test/lsmtest2.c │ 5 │
│ sqlite-master/ext/lsm1/lsm-test/lsmtest3.c │ 5 │
│ sqlite-master/ext/lsm1/lsm-test/lsmtest4.c │ 5 │
└────────────────────────────────────────────┴───────┘
*/
```
--------------------------------
### Comprehensive File Path Analysis in Python with sqlite-path
Source: https://context7.com/asg017/sqlite-path/llms.txt
A Python example demonstrating various sqlite-path functions including path_dirname(), path_basename(), path_name(), path_extension(), and path_length(). It loads the extension into an in-memory SQLite database and analyzes sample file paths.
```python
import sqlite3
import sqlite_path
db = sqlite3.connect(':memory:')
db.enable_load_extension(True)
sqlite_path.load(db)
# Create sample data
db.execute('''
CREATE TABLE files (path TEXT)
''')
db.executemany('INSERT INTO files VALUES (?)', [
('/home/user/documents/report.pdf',),
('/home/user/documents/data.csv',),
('/home/user/images/photo.jpg',),
('/var/log/system.log',),
('/usr/local/bin/python3',),
])
# Analyze paths
results = db.execute('''
SELECT
path,
path_dirname(path) as directory,
path_basename(path) as filename,
path_name(path) as name,
path_extension(path) as ext,
path_length(path) as depth
FROM files
ORDER BY depth DESC
''').fetchall()
for row in results:
print(f"Path: {row[0]}")
print(f" Directory: {row[1]}")
print(f" Filename: {row[2]}")
print(f" Name: {row[3]}")
print(f" Extension: {row[4]}")
print(f" Depth: {row[5]}")
print()
```
--------------------------------
### Install and Load sqlite-path in Node.js (sqlite3)
Source: https://context7.com/asg017/sqlite-path/llms.txt
Illustrates how to load the sqlite-path extension into a Node.js SQLite database using the 'sqlite3' package. The code verifies the successful loading by retrieving the extension's version.
```javascript
import sqlite3 from "sqlite3";
import { getLoadablePath } from "sqlite-path";
const db = new sqlite3.Database(":memory:");
db.loadExtension(getLoadablePath());
db.get("select path_version() as version", (err, row) => {
console.log(row.version); // Output: v0.2.1
});
```
--------------------------------
### Install sqlite-path Python Package
Source: https://github.com/asg017/sqlite-path/blob/main/python/sqlite_path/README.md
Installs the sqlite-path Python package using pip. This package allows you to use the sqlite-path extension within your Python applications.
```bash
pip install sqlite-path
```
--------------------------------
### Get sqlite-path Version
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Retrieves the semantic version string of the current sqlite-path library version. This function takes no arguments.
```sql
select path_version();
-- "v0.0.0"
```
--------------------------------
### File Extension Histogram using fsdir() in SQL
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Demonstrates creating a histogram of file extensions in the current directory using the `fsdir()` function and `sqlite-path`'s `path_extension`. This example groups files by extension, counts them, and visualizes the counts with a simple bar chart.
```sql
select
path_extension(name),
count(*),
printf('%.*c', count(*), '*') as bar
from fsdir('.')
where path_extension(name) is not null
group by 1
order by 2 desc
limit 6;
/*
┌──────────────────────┬──────────┬────────────────────────────────────┐
│ path_extension(name) │ count(*) │ bar │
├──────────────────────┼──────────┼────────────────────────────────────┤
│ .md │ 34 │ ********************************** │
│ .sample │ 26 │ ************************** │
│ .c │ 21 │ ********************* │
│ .css │ 5 │ ***** │
│ .yml │ 4 │ **** │
│ .h │ 4 │ **** │
└──────────────────────┴──────────┴────────────────────────────────────┘
*/
```
--------------------------------
### Get sqlite-path Debug Information
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Returns a debug string containing detailed information about the sqlite-path library, including its version, build date, commit hash, and the version of the cwalk library it depends on. This function takes no arguments.
```sql
select path_debug();
/*
Version: v0.0.0
Date: 2022-08-19T17:27:14Z-0700
Source: 01cd76716130b739f3e33177740e92e7ad0cff35
cwalk version: v1.2.6
*/
```
--------------------------------
### path_part_at() / path_at()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns the path segment at the specified index. Positive indices start from 0 at the beginning; negative indices start from -1 at the end. Returns NULL if the index is out of bounds.
```APIDOC
## path_part_at() / path_at()
### Description
Returns the path segment at the specified index. Positive indices start from 0 at the beginning; negative indices start from -1 at the end. Returns NULL if the index is out of bounds.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to query.
- **index** (integer) - Required - The index of the path segment to retrieve. Positive for start, negative for end.
### Request Example
```sql
-- Positive indexing
select path_at('oppenheimer/projects/manhattan/README', 0);
select path_at('oppenheimer/projects/manhattan/README', 3);
select path_at('oppenheimer/projects/manhattan/README', 4); -- out of bounds
-- Negative indexing
select path_at('oppenheimer/projects/manhattan/README', -1);
select path_at('oppenheimer/projects/manhattan/README', -2);
select path_at('oppenheimer/projects/manhattan/README', -5); -- out of bounds
-- Using alias
select path_part_at('foo/bar/baz.txt', 0);
```
### Response
#### Success Response (string or NULL)
- **segment** (string) - The path segment at the specified index, or NULL if out of bounds.
#### Response Example
```
"oppenheimer"
"README"
NULL
"README"
"manhattan"
NULL
"foo"
```
```
--------------------------------
### Get Path Segment at Index
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Retrieves a specific path segment from a given path string based on an index. Positive indices count from the start (0-based), and negative indices count from the end (-1 for the last segment). Returns NULL if the index is out of bounds. Aliased as `path_at`.
```sql
select path_at('oppenheimer/projects/manhattan/README', 0); -- 'oppenheimer'
select path_at('oppenheimer/projects/manhattan/README', 1); -- 'projects'
select path_at('oppenheimer/projects/manhattan/README', 2); -- 'manhattan'
select path_at('oppenheimer/projects/manhattan/README', 3); -- 'README'
select path_at('oppenheimer/projects/manhattan/README', 4); -- NULL
select path_at('oppenheimer/projects/manhattan/README', -1); -- 'README'
select path_at('oppenheimer/projects/manhattan/README', -2); -- 'manhattan'
select path_at('oppenheimer/projects/manhattan/README', -5); -- NULL
```
--------------------------------
### Get Path Extension
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts and returns the file extension of a given path string (including the leading dot). Returns NULL if the path has no extension or cannot be calculated. It takes a single argument: the path string.
```sql
select path_extension('spiderman.mp4'); -- ".mp4"
select path_extension('CHANGELOG'); -- NULL
```
--------------------------------
### Get Path Root
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts and returns the root portion of a given path string (e.g., '/' for Unix-like systems). Returns NULL if the root cannot be computed. It takes a single argument: the path string.
```sql
select path_root('/usr/bin'); -- '/'
```
--------------------------------
### Get Path Name
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts and returns the name of a given path string (the part without the extension). Returns NULL if the name cannot be calculated. It takes a single argument: the path string.
```sql
select path_name('spiderman.mp4'); -- "spiderman"
select path_name('archive.tar.gz'); -- "archive"
select path_name('CHANGELOG'); -- "CHANGELOG"
```
--------------------------------
### Get Path Basename
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts and returns the basename (the final component) of a given path string. Returns NULL if the basename cannot be calculated. It takes a single argument: the path string.
```sql
select path_basename('movies/spiderman.mp4');
-- "spiderman.mp4"
```
--------------------------------
### Get Path Directory Name
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts and returns the directory name (the path leading up to the basename) of a given path string. Returns NULL if the directory name cannot be calculated. It takes a single argument: the path string.
```sql
select path_dirname('movies/spiderman.mp4');
-- "movies/"
```
--------------------------------
### Get sqlite-path Extension Version
Source: https://context7.com/asg017/sqlite-path/llms.txt
This SQL query returns the semantic version string of the currently loaded sqlite-path extension. It's a simple way to confirm the extension is active and check its version.
```sql
select path_version();
-- Output: "v0.2.1"
```
--------------------------------
### Extract Path Segments with path_at() / path_part_at() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_at()` and its alias `path_part_at()` functions retrieve a specific segment from a path based on its index. Positive indices count from the start (0-based), while negative indices count from the end (-1-based). If the index is invalid or out of bounds, the function returns NULL.
```sql
-- Positive indexing (from start)
select path_at('oppenheimer/projects/manhattan/README', 0);
-- Output: "oppenheimer"
select path_at('oppenheimer/projects/manhattan/README', 1);
-- Output: "projects"
select path_at('oppenheimer/projects/manhattan/README', 2);
-- Output: "manhattan"
select path_at('oppenheimer/projects/manhattan/README', 3);
-- Output: "README"
select path_at('oppenheimer/projects/manhattan/README', 4);
-- Output: NULL (out of bounds)
-- Negative indexing (from end)
select path_at('oppenheimer/projects/manhattan/README', -1);
-- Output: "README"
select path_at('oppenheimer/projects/manhattan/README', -2);
-- Output: "manhattan"
select path_at('oppenheimer/projects/manhattan/README', -5);
-- Output: NULL (out of bounds)
-- Using path_part_at (alias)
select path_part_at('foo/bar/baz.txt', 0);
-- Output: "foo"
```
--------------------------------
### Check for Absolute Paths with path_absolute() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_absolute()` function determines if a given path string represents an absolute path. It returns 1 if the path is absolute (e.g., starts with '/') and 0 if it is relative. This function helps differentiate between system-wide and relative file locations.
```sql
select path_absolute('/usr/local/bin');
-- Output: 1
select path_absolute('./rel/to/me');
-- Output: 0
select path_absolute('relative/path');
-- Output: 0
select path_absolute('/');
-- Output: 1
```
--------------------------------
### Load sqlite-path Extension with better-sqlite3
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Demonstrates how to load the sqlite-path extension into a better-sqlite3 database instance. It imports the necessary libraries, creates a database connection, loads the extension using getLoadablePath(), and then queries for the extension's version.
```javascript
import Database from "better-sqlite3";
import * as sqlite_path from "sqlite-path";
const db = new Database(":memory:");
db.loadExtension(sqlite_path.getLoadablePath());
const version = db.prepare("select path_version()").pluck().get();
console.log(version); // "v0.2.0"
```
--------------------------------
### Load sqlite-path Extension with node-sqlite3
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Illustrates loading the sqlite-path extension with the node-sqlite3 library. It shows the import statements, database creation, extension loading via getLoadablePath(), and a callback-based query to retrieve the extension version.
```javascript
import sqlite3 from "sqlite3";
import * as sqlite_path from "sqlite-path";
const db = new sqlite3.Database(":memory:");
db.loadExtension(sqlite_path.getLoadablePath());
db.get("select path_version()", (err, row) => {
console.log(row); // {json_schema_version(): "v0.2.0"}
});
```
--------------------------------
### Determine Supported Platform
Source: https://github.com/asg017/sqlite-path/blob/main/npm/sqlite-path/README.md
Shows how to check the current Node.js platform and architecture using process.platform and process.arch. This is useful for verifying compatibility with the sqlite-path NPM package.
```bash
$ node -e 'console.log([process.platform, process.arch])'
[ 'darwin', 'x64' ]
```
--------------------------------
### Load SQLite Path Extension in Deno
Source: https://github.com/asg017/sqlite-path/blob/main/deno/README.md
Demonstrates how to load the sqlite-path extension into a Deno SQLite database using the x/sqlite3 module. It imports necessary modules, initializes a database, enables extension loading, and then loads the extension using its path. Finally, it queries the extension's version.
```javascript
import { Database } from "https://deno.land/x/sqlite3@0.8.0/mod.ts";
import * as sqlite_path from "https://deno.land/x/sqlite_path@v0.2.1/mod.ts";
const db = new Database(":memory:");
db.enableLoadExtension = true;
db.loadExtension(sqlite_path.getLoadablePath());
const [version] = db
.prepare("select path_version()")
.value<[string]>()!;
console.log(version);
```
--------------------------------
### Load sqlite-path as a Runtime Extension in SQLite CLI
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Demonstrates how to load the sqlite-path extension dynamically into the SQLite command-line interface (CLI). This allows you to use the extension's functions directly within SQL queries.
```sql
.load ./path0
select path_version();
-- v0.0.1
```
--------------------------------
### path_join()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Joins two or more path segments together into a single path. Requires at least two arguments.
```APIDOC
## path_join()
### Description
Joins two or more path segments together into a single path. Requires at least two arguments.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **segments** (string) - Required - One or more path segments to join.
### Request Example
```sql
select path_join('src', 'index.js');
select path_join('a', 'b', 'c');
select path_join('/usr', 'local', 'bin', 'sqlite3');
select path_join('projects', 'webapp', 'src', 'components', 'Button.tsx');
```
### Response
#### Success Response (string)
- **joined_path** (string) - The combined path string.
#### Response Example
```
"src/index.js"
"a/b/c"
"/usr/local/bin/sqlite3"
"projects/webapp/src/components/Button.tsx"
```
```
--------------------------------
### Deno Run Permissions for SQLite Path
Source: https://github.com/asg017/sqlite-path/blob/main/deno/README.md
Shows the command-line flags required to run a Deno script that utilizes the x/sqlite_path module. It highlights the need for `--allow-ffi` and `--unstable` permissions, often consolidated with `--allow-all` or `-A`.
```bash
deno run -A --unstable
```
--------------------------------
### Load sqlite-path as a Runtime Extension in Node.js
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Illustrates how to load and utilize the sqlite-path extension in a Node.js application using the `better-sqlite3` library. This facilitates the integration of SQLite extension functions into your JavaScript backend.
```javascript
const Database = require("better-sqlite3");
const db = new Database(":memory:");
db.loadExtension("./path0");
console.log(db.prepare("select path_version()" ).get());
# { 'html_version()': 'v0.0.1' }
```
--------------------------------
### Basic Path Parsing Functions in SQL
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Demonstrates the usage of fundamental path parsing functions like `path_dirname`, `path_basename`, and `path_extension`. These functions are essential for extracting specific components from file paths within SQLite.
```sql
.load ./path0
select path_dirname('foo/bar.txt'); -- 'foo/'
select path_basename('foo/bar.txt'); -- 'bar.txt'
select path_extension('foo/bar.txt'); -- '.txt'
select path_part_at('foo/bar/baz.txt', 0); -- 'foo'
select path_part_at('foo/bar/baz.txt', 1); -- 'bar'
select path_part_at('foo/bar/baz.txt', -1); -- 'baz.txt'
```
--------------------------------
### Publish Datasette with datasette-sqlite-path Plugin
Source: https://github.com/asg017/sqlite-path/blob/main/python/datasette_sqlite_path/README.md
Publishes a Datasette instance to Google Cloud Run, including the datasette-sqlite-path plugin. This ensures the path extension is available in the deployed service.
```bash
datasette publish cloudrun data.db --service=my-service --install=datasette-sqlite-path
```
--------------------------------
### Load sqlite-path as a Runtime Extension in Python
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Shows how to load and use the sqlite-path extension within a Python script using the built-in `sqlite3` module. This enables programmatic access to the extension's functionality.
```python
import sqlite3
con = sqlite3.connect(":memory:")
con.enable_load_extension(True)
con.load_extension("./path0")
print(con.execute("select path_version()" ).fetchone())
# ('v0.0.1',)
```
--------------------------------
### Iterating Through Path Parts in SQL
Source: https://github.com/asg017/sqlite-path/blob/main/README.md
Shows how to use the `path_parts` function to iterate over individual components of a given file path. This is useful for analyzing the structure of paths, such as file system paths.
```sql
select *
from path_parts('/usr/bin/sqlite3');
/*
┌────────┬─────────┐
│ type │ part │
├────────┼─────────┤
│ normal │ usr │
│ normal │ bin │
│ normal │ sqlite3 │
└────────┴─────────┘
*/
```
--------------------------------
### Load sqlite-path Extension into SQLite Connection
Source: https://github.com/asg017/sqlite-path/blob/main/python/sqlite_path/README.md
Loads the sqlite-path extension into a given sqlite3.Connection object by calling Connection.load_extension(). It includes enabling and disabling extension loading for security.
```python
import sqlite_path
import sqlite3
conn = sqlite3.connect(':memory:')
conn.enable_load_extension(True)
sqlite_path.load(conn)
conn.enable_load_extension(False)
conn.execute('select path_version()').fetchone()
# ('v0.1.0')
```
--------------------------------
### Path Debug API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Provides detailed debugging information about the sqlite-path library, including version, build date, and commit hash.
```APIDOC
## GET /path_debug
### Description
Returns a debug string containing various information about sqlite-path, including the version string, build date, commit hash, and cwalk version.
### Method
GET
### Endpoint
/path_debug
### Parameters
None
### Request Example
```sql
select path_debug();
```
### Response
#### Success Response (200)
- **debug_info** (string) - A multi-line string with debug details.
#### Response Example
```json
{
"debug_info": "Version: v0.0.0\nDate: 2022-08-19T17:27:14Z-0700\nSource: 01cd76716130b739f3e33177740e92e7ad0cff35\ncwalk version: v1.2.6"
}
```
```
--------------------------------
### path_length()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns the number of segments in a path.
```APIDOC
## path_length()
### Description
Returns the number of segments in a path.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to measure.
### Request Example
```sql
select path_length('foo/bar/baz.txt');
select path_length('/usr/local/bin/sqlite3');
select path_length('single');
```
### Response
#### Success Response (integer)
- **segment_count** (integer) - The total number of segments in the path.
#### Response Example
```
3
4
1
```
```
--------------------------------
### Path Join API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Joins two or more path strings together into a single path.
```APIDOC
## GET /path_join
### Description
Join two or more paths together, or null if it cannot be computed.
### Method
GET
### Endpoint
/path_join
### Parameters
#### Query Parameters
- **paths** (string array) - Required - An array of path strings to join.
### Request Example
```sql
select path_join('src', 'index.js'); -- 'src/index.js'
select path_join('a', 'b', 'c'); -- 'a/b/c'
```
### Response
#### Success Response (200)
- **joined_path** (string or null) - The combined path string, or NULL if not computable.
#### Response Example
```json
{
"joined_path": "src/index.js"
}
```
```
--------------------------------
### path_normalize()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Normalizes a path by resolving `.` (current directory) and `..` (parent directory) segments, returning a clean canonical path.
```APIDOC
## path_normalize()
### Description
Normalizes a path by resolving `.` (current directory) and `..` (parent directory) segments, returning a clean canonical path.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to normalize.
### Request Example
```sql
select path_normalize('a/x/../b/c');
select path_normalize('/usr/local/../bin/./sqlite3');
select path_normalize('./foo/bar/../baz');
```
### Response
#### Success Response (string)
- **normalized_path** (string) - The normalized path string.
#### Response Example
```
"a/b/c"
"/usr/bin/sqlite3"
"foo/baz"
```
```
--------------------------------
### Path Extension API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts the file extension from a given path string.
```APIDOC
## GET /path_extension
### Description
Returns the extension of the given path as text, or NULL if it cannot be calculated.
### Method
GET
### Endpoint
/path_extension
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string from which to extract the extension.
### Request Example
```sql
select path_extension('spiderman.mp4'); -- ".mp4"
select path_extension('CHANGELOG'); -- NULL
```
### Response
#### Success Response (200)
- **extension** (string or null) - The file extension, or NULL if not calculable.
#### Response Example
```json
{
"extension": ".mp4"
}
```
```
--------------------------------
### path_root()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns the root portion of the given path, or an empty string for relative paths.
```APIDOC
## path_root()
### Description
Returns the root portion of the given path, or an empty string for relative paths.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to extract the root from.
### Request Example
```sql
select path_root('/usr/bin');
select path_root('relative/path');
```
### Response
#### Success Response (string)
- **root** (string) - The root part of the path, or an empty string.
#### Response Example
```
"/"
""
```
```
--------------------------------
### Path Root API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts the root directory from a given path string.
```APIDOC
## GET /path_root
### Description
Returns the root portion of the given path, or null if it cannot be computed.
### Method
GET
### Endpoint
/path_root
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string from which to extract the root.
### Request Example
```sql
select path_root('/usr/bin');
```
### Response
#### Success Response (200)
- **root** (string or null) - The root portion of the path, or NULL if not computable.
#### Response Example
```json
{
"root": "/"
}
```
```
--------------------------------
### Path Normalize API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Normalizes a given path string by resolving back-references (e.g., '..').
```APIDOC
## GET /path_normalize
### Description
Create a normalized version of the given path (resolving back segments), or null if it cannot be computed.
### Method
GET
### Endpoint
/path_normalize
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string to normalize.
### Request Example
```sql
select path_normalize('a/x/../b/c');
```
### Response
#### Success Response (200)
- **normalized_path** (string or null) - The normalized path string, or NULL if not computable.
#### Response Example
```json
{
"normalized_path": "a/b/c"
}
```
```
--------------------------------
### path_intersection()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns the common path prefix shared between two paths, or NULL if there is no common portion.
```APIDOC
## path_intersection()
### Description
Returns the common path prefix shared between two paths, or NULL if there is no common portion.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path1** (string) - Required - The first path.
- **path2** (string) - Required - The second path.
### Request Example
```sql
select path_intersection('/foo/bar/a', '/foo/bax/a');
select path_intersection('/usr/local/bin', '/usr/local/lib');
select path_intersection('/home/user/docs', '/var/log');
```
### Response
#### Success Response (string or NULL)
- **common_prefix** (string) - The common path prefix, or NULL if none exists.
#### Response Example
```
"/foo"
"/usr/local"
NULL
```
```
--------------------------------
### path_absolute()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns 1 if the given path is an absolute path, 0 otherwise.
```APIDOC
## path_absolute()
### Description
Returns 1 if the given path is an absolute path, 0 otherwise.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The path to check.
### Request Example
```sql
select path_absolute('/usr/local/bin');
select path_absolute('./rel/to/me');
select path_absolute('relative/path');
select path_absolute('/');
```
### Response
#### Success Response (integer)
- **is_absolute** (integer) - 1 if absolute, 0 if relative.
#### Response Example
```
1
0
0
1
```
```
--------------------------------
### sqlite-path Functions
Source: https://context7.com/asg017/sqlite-path/llms.txt
This section details the scalar and table-valued functions provided by the sqlite-path extension for path manipulation.
```APIDOC
## path_version()
### Description
Returns the semantic version string of the currently loaded sqlite-path extension.
### Method
SQL Function
### Endpoint
N/A
### Parameters
None
### Request Example
```sql
select path_version();
```
### Response
#### Success Response (200)
- **version** (string) - The version string of the sqlite-path extension.
#### Response Example
```json
{
"version": "v0.2.1"
}
```
## path_debug()
### Description
Returns detailed debug information about sqlite-path including version, build date, source commit hash, and the cwalk library version used.
### Method
SQL Function
### Endpoint
N/A
### Parameters
None
### Request Example
```sql
select path_debug();
```
### Response
#### Success Response (200)
- **debug_info** (string) - A multi-line string containing debug information.
#### Response Example
```text
Version: v0.2.1
Date: 2022-08-19T17:27:14Z-0700
Source: 01cd76716130b739f3e33177740e92e7ad0cff35
cwalk version: v1.2.6
```
## path_dirname(path)
### Description
Returns the directory portion of a path as text, or NULL if it cannot be calculated. The function returns the path up to and including the final separator.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The file path to process.
### Request Example
```sql
select path_dirname('movies/spiderman.mp4');
```
### Response
#### Success Response (200)
- **dirname** (string) - The directory portion of the path.
#### Response Example
```json
{
"dirname": "movies/"
}
```
## path_basename(path)
### Description
Returns the final component of a path (the filename including extension), or NULL if it cannot be calculated.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The file path to process.
### Request Example
```sql
select path_basename('/usr/local/bin/sqlite3');
```
### Response
#### Success Response (200)
- **basename** (string) - The base name (filename with extension) of the path.
#### Response Example
```json
{
"basename": "sqlite3"
}
```
## path_extension(path)
### Description
Returns the file extension of a path including the leading dot, or NULL if the file has no extension.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The file path to process.
### Request Example
```sql
select path_extension('archive.tar.gz');
```
### Response
#### Success Response (200)
- **extension** (string) - The file extension including the leading dot.
#### Response Example
```json
{
"extension": ".gz"
}
```
## path_name(path)
### Description
Returns the filename without the extension. For files with multiple extensions (like `.tar.gz`), only the first extension is stripped.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - Required - The file path to process.
### Request Example
```sql
select path_name('archive.tar.gz');
```
### Response
#### Success Response (200)
- **name** (string) - The filename without the first extension.
#### Response Example
```json
{
"name": "archive"
}
```
```
--------------------------------
### path_relative()
Source: https://context7.com/asg017/sqlite-path/llms.txt
Returns 1 if the given path is a relative path, 0 if it is absolute, or NULL if the path is NULL.
```APIDOC
## path_relative()
### Description
Returns 1 if the given path is a relative path, 0 if it is absolute, or NULL if the path is NULL.
### Method
SQL Function
### Endpoint
N/A
### Parameters
#### Path Parameters
- **path** (string) - The path to check.
### Request Example
```sql
select path_relative('./rel/to/me');
select path_relative('relative/path');
select path_relative('/usr/local/bin');
```
### Response
#### Success Response (integer or NULL)
- **is_relative** (integer) - 1 if relative, 0 if absolute, NULL if input is NULL.
#### Response Example
```
1
1
0
```
```
--------------------------------
### Path Name API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts the filename without the extension (name) from a given path string.
```APIDOC
## GET /path_name
### Description
Returns the name of the given path as text, or NULL if it cannot be calculated.
### Method
GET
### Endpoint
/path_name
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string from which to extract the name.
### Request Example
```sql
select path_name('spiderman.mp4'); -- "spiderman"
select path_name('archive.tar.gz'); -- "archive"
select path_name('CHANGELOG'); -- "CHANGELOG"
```
### Response
#### Success Response (200)
- **name** (string or null) - The name of the path, or NULL if not calculable.
#### Response Example
```json
{
"name": "spiderman"
}
```
```
--------------------------------
### Path Dirname API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts the directory name (dirname) from a given path string.
```APIDOC
## GET /path_dirname
### Description
Returns the dirname of the given path as text, or NULL if it cannot be calculated.
### Method
GET
### Endpoint
/path_dirname
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string from which to extract the dirname.
### Request Example
```sql
select path_dirname('movies/spiderman.mp4');
```
### Response
#### Success Response (200)
- **dirname** (string or null) - The dirname of the path, or NULL if not calculable.
#### Response Example
```json
{
"dirname": "movies/"
}
```
```
--------------------------------
### Path Basename API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Extracts the filename (basename) from a given path string.
```APIDOC
## GET /path_basename
### Description
Returns the basename of the given path as text, or NULL if it cannot be calculated.
### Method
GET
### Endpoint
/path_basename
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string from which to extract the basename.
### Request Example
```sql
select path_basename('movies/spiderman.mp4');
```
### Response
#### Success Response (200)
- **basename** (string or null) - The basename of the path, or NULL if not calculable.
#### Response Example
```json
{
"basename": "spiderman.mp4"
}
```
```
--------------------------------
### Normalize Path
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Creates a normalized version of a given path string by resolving relative segments like '..' and '.'. Returns NULL if normalization cannot be computed. It takes a single argument: the path string to normalize.
```sql
select path_normalize('a/x/../b/c');
-- "a/b/c"
```
--------------------------------
### Join Path Segments with path_join() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_join()` function concatenates two or more path segments into a single, unified path string. It requires at least two arguments to perform the join operation. This function is useful for constructing file paths programmatically.
```sql
select path_join('src', 'index.js');
-- Output: "src/index.js"
select path_join('a', 'b', 'c');
-- Output: "a/b/c"
select path_join('/usr', 'local', 'bin', 'sqlite3');
-- Output: "/usr/local/bin/sqlite3"
select path_join('projects', 'webapp', 'src', 'components', 'Button.tsx');
-- Output: "projects/webapp/src/components/Button.tsx"
```
--------------------------------
### Path Absolute API
Source: https://github.com/asg017/sqlite-path/blob/main/docs.md
Checks if a given path string represents an absolute path.
```APIDOC
## GET /path_absolute
### Description
Returns 1 if the given path is absolute, 0 otherwise.
### Method
GET
### Endpoint
/path_absolute
### Parameters
#### Query Parameters
- **path** (string) - Required - The path string to check.
### Request Example
```sql
select path_absolute("/usr/local/bin"); -- 1
select path_absolute("./rel/to/me"); -- 0
```
### Response
#### Success Response (200)
- **is_absolute** (integer) - 1 if the path is absolute, 0 otherwise.
#### Response Example
```json
{
"is_absolute": 1
}
```
```
--------------------------------
### Extract Root Directory with path_root() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_root()` function extracts the root directory component from a given path. For absolute paths, it returns the root (e.g., '/'); for relative paths, it returns an empty string. This is useful for isolating the top-level directory of a path.
```sql
select path_root('/usr/bin');
-- Output: "/"
select path_root('relative/path');
-- Output: ""
```
--------------------------------
### Normalize Paths with path_normalize() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_normalize()` function cleans up a given path by resolving special directory segments like `.` (current directory) and `..` (parent directory). It returns a canonical and simplified representation of the path. This is essential for ensuring path consistency.
```sql
select path_normalize('a/x/../b/c');
-- Output: "a/b/c"
select path_normalize('/usr/local/../bin/./sqlite3');
-- Output: "/usr/bin/sqlite3"
select path_normalize('./foo/bar/../baz');
-- Output: "foo/baz"
```
--------------------------------
### Check for Relative Paths with path_relative() in SQL
Source: https://context7.com/asg017/sqlite-path/llms.txt
The `path_relative()` function checks if a given path is relative. It returns 1 for relative paths, 0 for absolute paths, and NULL if the input path is NULL. This complements `path_absolute()` by providing the opposite boolean check.
```sql
select path_relative('./rel/to/me');
-- Output: 1
select path_relative('relative/path');
-- Output: 1
select path_relative('/usr/local/bin');
-- Output: 0
```