
Security News
Scaling Socket from Zero to 10,000+ Organizations
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.
@lazycatcloud/minidb
Advanced tools
minidb 目前只有一个远程db的实现,使用 lzcinit 中 minidb 作为后端服务。
import { MiniDB } from "@lazycatcloud/minidb";
const db = new MiniDB();
const collection = db.getCollection("awesome");
下面是一个 minidb 支持的查询语句例子
import { MiniDB } from "@lazycatcloud/minidb";
const db = new MiniDB();
const collection = db.getCollection("example");
async function mock() {
const docs = [...Array(100)].map((_, index) => {
const doc = {
index,
name: `name-${index}`,
};
if (index == 99) {
doc.last = true;
}
return doc;
});
return collection.upsert(docs);
}
async function main() {
await mock();
// 根据 $in 查询, sort 默认升序
await collection
.find({ index: { $in: [0, 1, 2, 3, 4, 5] } }, { sort: ["index"] })
.fetch()
.then((res) => {
res.forEach((e, index) => {
console.assert(e.index === index, "output element index error");
});
});
// 根据 $eq 查询, 查询对应的元素等于对应的值
await collection.findOne({ index: 5 }).then((res) => {
console.assert(res.index === 5);
});
await collection.findOne({ index: { $eq: 5 } }).then((res) => {
console.assert(res.index === 5);
});
// 根据 $gt 查询大于指定条件的数据
await collection
.find({ index: { $gt: 90 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 9);
res.forEach((r) => {
console.assert(r.index > 90);
});
});
// 根据 $gte 查询大于等于指定条件的数据
await collection
.find({ index: { $gte: 90 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 10);
res.forEach((r) => {
console.assert(r.index >= 90);
});
});
// 根据 $lt 查询小于指定条件的数据
await collection
.find({ index: { $lt: 9 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 9);
res.forEach((r) => {
console.assert(r.index < 9);
});
});
// 根据 $lte 查询小于等于指定条件的数据
await collection
.find({ index: { $lte: 9 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 10);
res.forEach((r) => {
console.assert(r.index <= 9);
});
});
// 结合 $gte 和 $lte 一起使用,获取范围内的数据
await collection
.find({ index: { $lte: 10, $gte: 5 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 6);
res.forEach((r) => {
console.assert(r.index <= 10 && r.index >= 5);
});
});
// 根据 $ne 查询不等于某个值的数据, $ne 这个目前有 bug 先不要用
await collection
.find({ index: { $lte: 10, $gte: 5, $ne: 6 } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 5);
res.forEach((r) => {
console.assert(r.index <= 10 && r.index >= 5 && r.index !== 6);
});
});
// 根据 $exists 查询存在某一个字段
await collection
.find({ $exists: "last" }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 1);
res.forEach((r) => {
console.assert(r.index == 99);
});
});
// 根据 $like 查询匹配的数据
await collection
.find({ name: { $like: `name-1` } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 11);
res.forEach((r) => {
console.assert(r.index == 1 || (r.index >= 10 && r.index <= 19));
});
});
// $like 中还可以使用正则表达式来匹配
await collection
.find({ name: { $like: `name-1[5678]` } }, { sort: ["index"] })
.fetch()
.then((res) => {
console.assert(res.length === 4);
res.forEach((r) => {
console.assert(r.index >= 15 && r.index <= 18);
});
});
await db.removeCollection("example");
}
main();
FAQs
lazycat cloud mini database
We found that @lazycatcloud/minidb demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 12 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket CEO Feross Aboukhadijeh shares lessons from scaling a developer security startup to 10,000+ organizations in this founder interview.

Research
Socket Threat Research maps a rare inside look at OtterCookie’s npm-Vercel-GitHub chain, adding 197 malicious packages and evidence of North Korean operators.

Research
Socket researchers identified a malicious Chrome extension that manipulates Raydium swaps to inject an undisclosed SOL transfer, quietly routing fees to an attacker wallet.