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

notadb

v0.0.13

Published

this is not a database

Downloads

77

Readme

Notadb

Notadb is a shortened for "Not a database".
This library is you can do duck typing using a set schema.

Install

yarn add notadb

How to use

import { Model } from "notadb";

const post = new Model([{ id: 2 }]);
const res = post.find(2);
/* res
{
  id: 2,
  key: "",
  link: "",
  type: "post",
  author: {},
  subject: "",
  description: "",
  thumbnail: "",
  media: [],
  properties: {},
  metadata: [],
  relations: [],
  createdAt: "1977-01-01T00:00:00.0000",
  updatedAt: "1977-01-01T00:00:00.0000",
}
*/

Schema

Record

| key | type | default | description | | ----------- | ---------- | ---------------- | ---------------- | | id | number | -1 | primary key | | key | string | "" | hash key | | link | string | "" | page link | | type | string | post | post type | | author | Author | {} | user | | subject | string | "" | subject | | description | string | "" | description | | thumbnail | string | "" | image url | | media | Media | [] | Media type | | metadata | Metadata[] | [] | | | properties | Properties | {} | | | relations | Record[] | [] | relations record | | createdAt | Date | current datetime | create datetime | | updatedAt | Date | current datetime | update datetime |


Author

| key | type | default | description | | ------ | ------ | ------- | ----------- | | id | number | -1 | - | | name | string | "" | - | | avatar | string | "" | image url |

Media

| key | type | default | description | | -------- | ------ | ------- | ----------- | | url | string | "" | - | | mimetype | string | "" | - |

Metadata

| key | type | default | description | | ----- | ------ | ------- | ----------- | | label | string | "" | - | | name | string | "" | - | | value | any | "" | - |


Properties

| key | type | default | description | | ----- | ------ | ------- | ----------- | | name | string | "" | - | | value | any | "" | - |

Model

Insert

const posts = new Model();
posts.insert({ id: 2 });

// or

const posts = new Model([{ id: 2 }]);

// => Model

Update

const posts = new Model([{ id: 2 }]);
posts.update(2, { subject: "update" });

// => Model

Destroy

const posts = new Model([{ id: 2 }, { id: 3 }]);
posts.destroy(2);
// => Model

all

const posts = new Model([
  { id: 2, subject: "a" },
  { id: 3, subject: "b" },
  { id: 4, subject: "b" },
]);
posts.all();
// => Record[] [ { id: 3, subject: "b", ...}, {id: 4, subject: "b", ...} ]

find

// find by id
const posts = new Model([
  { id: 2, subject: "a" },
  { id: 3, subject: "b" },
  { id: 4, subject: "b" },
]);
posts.find(2);
// => Record { id: 2, subject: "a", ...}

findBy

const posts = new Model([
  { id: 2, subject: "a" },
  { id: 3, subject: "b" },
  { id: 4, subject: "b" },
]);

posts.findBy("subject", "b");
// => Record { id: 3, subject: "b", ...}

findAll

const posts = new Model([
  { id: 2, subject: "a" },
  { id: 3, subject: "b" },
  { id: 4, subject: "b" },
]);

posts.findAll("subject", "b");
// => Record[] [ { id: 3, subject: "b", ...}, {id: 4, subject: "b", ...} ]

head

const posts = new Model(
  Array(10)
    .fill(0)
    .map((v, index) => ({
      id: v + index + 1,
      subject: Number(index).toString(16),
    }))
);

posts.head();
// => Record { id: 1, subject: "b", ...}

last

const posts = new Model(
  Array(10)
    .fill(0)
    .map((v, index) => ({
      id: v + index + 1,
      subject: Number(index).toString(16),
    }))
);

posts.last();
// => Record { id: 10, subject: "b", ...}

drop

const posts = new Model(
  Array(10)
    .fill(0)
    .map((v, index) => ({
      id: v + index + 1,
      subject: Number(index).toString(16),
    }))
);
posts.drop(1); // count
// => Record [{ id: 2, subject: "b", ...}, { id: 3, subject: "b", ...}]

Record

Get Property

const posts = new Model([
  {
    id: 1,
    subject: "title",
    properties: { like: { label: "like", value: 11 } },
  },
]);

const res = posts.find(1);
res.prop("like");
// => 11

Set Property

const posts = new Model([
  {
    id: 1,
    subject: "title",
    properties: { like: { label: "like", value: 1 } },
  },
]);

const res = posts.find(1);
res.prop("like", 11);
// => 11

All property

If you don't put in the key, everything will be returned.

const posts = new Model([
  {
    id: 1,
    subject: "title",
    properties: {
      like: { label: "like", value: 11 },
      bookmark: { label: "bookmark", value: 12 },
    },
  },
]);

const res = posts.find(1);
const props = res.prop();
// => { like: 11, bookmark: 12 }

Get Metadata

const posts = new Model([
  {
    id: 1,
    subject: "title",
    metadata: [{ label: "like", name: "like", value: 12 }],
  },
]);

const res = posts.find(1);
res.meta("like");
// => 12

Set Metadata

const posts = new Model([
  {
    id: 1,
    subject: "title",
    metadata: [{ label: "like", name: "like", value: 1 }],
  },
]);

const res = posts.find(1);
res.meta("like", 12);
// => 12

All metadata

If you don't put in the key, everything will be returned.

Metadata is good to apply to form.

const posts = new Model([
  {
    id: 1,
    subject: "title",
    metadata: [
      { label: "like", name: "like", value: 12 },
      { label: "bookmark", name: "bookmark", value: 13 },
    ],
  },
]);

const res = posts.find(1);
res.meta();
// => [ { name: "like", value: 12 }, { name: "bookmark", value: 13 } ]

Enumeration

You can enumeration Metadata[] or Property format

const record = new Record({
  id: 1,
  subject: "title",
  // like Metadata[]
  array: [
    { label: "temp", name: "a", value: 1 },
    { label: "temp", name: "b", value: 2 },
  ],

  // like Property
  object: {
    a: { label: "temp", value: 1 },
    b: { label: "temp", value: 2 },
  },
}) as Record & { array: Metadata[]; object: Property };

const metas = record.enum(record.array);
// => { a: 1, b: 2}

const props = record.enum(record.object);
// => { a: 1, b: 2}

Facade


Facade.author(1, 'b', 'http://www.domain.com');
// => { id: 1, name: 'b', avatar: 'http://www.domain.com' }

Facade.meta('a', 'b', 'c');
// => { label: 'a', name: 'b', value: 'c' }

Facade.prop('a', 'b', 'c');
// => { 'a': { name: 'b', value: 'c' } }

Facade.timestamps(new Date('2022-01-01'));
// => { createdAt: Date, updatedAt: Date }

example

  {
    ...Facade.author(1, 'b', 'http://www.domain.com'),
    properties: Object.assign.apply(Object, [
        Facade.prop("like", "like", 1),
        Facade.prop("bookmark", "bookmark", 0),
    ]),
    metadata: [
      Facade.meta("like", "like", 1),
      Facade.meta("bookmark", "bookmark", 0),
    ],
    ...Facade.timestamps(new Date('2022-01-01'))
  }

Events

const posts = new Model([{ id: 2 }]);

posts.on("created", () => {}); // { target: Model }
posts.on("inserted", () => {}); // { record: Object, target: Model }
posts.on("updated", () => {}); // { record: Object, target: Model }
posts.on("destroyed", () => {}); // { record: Object, target: Model }
posts.on("truncated", () => {}); // { }
posts.on("changed", () => {}); // { type: string, target: Model }