12个版本
0.4.0 | 2024年2月18日 |
---|---|
0.3.0 | 2024年2月16日 |
0.2.9 | 2024年2月16日 |
在 数据库接口 中排名 723
每月下载量 53
7KB
58 代码行
sqlite-uuid
为SQLite添加UUIDv4和UUIDv7支持
[!警告] 这是一个实验性插件
安装
wget -qO- "https://github.com/woile/sqlite-uuid/releases/download/0.4.0/libsqlite_uuid-$(uname -s)-$(uname -m).tar.gz" | tar xvz
使用方法
.load libsqlite_uuid
--- Let's try uuid_blob which produces a blob (smaller than text)
CREATE TABLE events(
event_id uuid_blob primary key,
name TEXT
);
INSERT INTO events(event_id, name) VALUES (uuid_blob(), 'up');
INSERT INTO events(event_id, name) VALUES (uuid_v7_blob(), 'down');
INSERT INTO events(event_id, name) VALUES (uuid_as_blob('018d9887-42cd-7115-b1ca-18227ac211b4'), 'down');
SELECT uuid_from_blob(event_id), name
FROM events
WHERE event_id = uuid_as_blob('018d9887-42cd-7115-b1ca-18227ac211b4');
--- Let's use uuid which produces strings
CREATE TABLE events_as_str(
event_id uuid primary key,
name TEXT
);
INSERT INTO events_as_str(event_id, name) VALUES (uuid(), 'up');
INSERT INTO events_as_str(event_id, name) VALUES (uuid(7), 'down');
SELECT event_id name FROM events_as_str;
函数
--- create a UUIDv4 as BLOB
uuid_blob()
--- create a UUIDv7 as BLOB (recommended)
uuid_v7_blob()
--- create a UUIDv4 as TEXT
uuid()
--- create a UUIDv7 as TEXT
uuid_v7()
--- convert TEXT UUID to BLOB
uuid_as_blob('018d9887-42cd-7115-b1ca-18227ac211b4')
--- convert UUID BLOB to TEXT
uuid_from_blob(column_name)
感谢 asg017 的出色工作,他构建了一个令人惊叹的 sqlite-ecosystem
依赖项
~13MB
~244K SLoC