npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@lazycatcloud/minidb

v0.0.11

Published

lazycat cloud mini database

Downloads

37

Readme

minidb

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();