Seeking an internship

๐Ÿ” Seeking a 6-month software engineering internship starting January 2027. Based in France, open to remote or relocation.
contact@julienc.me โ€ข Resume

sqlite-path

A loadable SQLite extension for parsing, generating, and querying paths. Based on cwalk

Try it out in your browser and learn more in Introducing sqlite-path: A SQLite extension for parsing and generating file paths (August 2022)

Usage

.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'

Iterate through all parts in a path.


select *
from path_parts('/usr/bin/sqlite3');

/*
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  type  โ”‚  part   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ normal โ”‚ usr     โ”‚
โ”‚ normal โ”‚ bin     โ”‚
โ”‚ normal โ”‚ sqlite3 โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
*/

Inside a ZIP archive of the SQLite source code, find the top 5 deepest .c source code files under the ext/ directory (using SQLite's ZIP support).

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     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
*/

Make a histogram of the count of file extensions in the current directory, using fsdir().


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        โ”‚ ****                               โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
*/

Documentation

See docs.md for a full API reference.

Installing

Language Install
Python pip install sqlite-path PyPI
Datasette datasette install datasette-sqlite-path Datasette
Node.js npm install sqlite-path npm
Deno deno.land/x/sqlite_path deno.land/x release
Ruby gem install sqlite-path Gem
Github Release GitHub tag (latest SemVer pre-release)

The Releases page contains pre-built binaries for Linux amd64, MacOS amd64 (no arm), and Windows.

As a loadable extension

If you want to use sqlite-path as a Runtime-loadable extension, Download the path0.dylib (for MacOS), path0.so (Linux), or path0.dll (Windows) file from a release and load it into your SQLite environment.

Note: The 0 in the filename (path0.dylib/ path0.so/path0.dll) denotes the major version of sqlite-path. Currently sqlite-path is pre v1, so expect breaking changes in future versions.

For example, if you are using the SQLite CLI, you can load the library like so:

.load ./path0
select path_version();
-- v0.0.1

Or in Python, using the builtin sqlite3 module:

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',)

Or in Node.js using better-sqlite3:

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' }

Or with Datasette:

datasette data.db --load-extension ./path0

See also