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

sqlite-cloudflare-d1

v0.0.2

Published

Ergonomic interface for writing sqlite queries against cloudflare d1

Downloads

1

Readme

sqlite-cloudflare-d1

This library provides a minimal and flexible interface for cloudflare d1.
The CURD operations are supported.

insert

Inserts a single row into and returns the inserted row.

Example:

insert(db, {
  into: "users",
  data: { name: "bob", age: 30 }
});
// { id: 1, name: "bob", age: 30 }

query

Query database for one or more rows. See the last example on how to join tables.

Example 1: Returns every row in albums table.

await query(db, { from: "albums" });
// [{id: 1, title: "Carry On"}, ...]

Example 2: Returns every album that starts with "Carry".

await query(db, {
  from: "albums",
  where: {
    "Title LIKE ?": "Carry%",
  },
});
// [{id: 1, title: "Carry On"}]

Example 3: A more complex query. Note that in "where" clauses objects mean "AND" and arrays mean "OR".

await query(db, {
  from: "albums",
  where: [
    { Title: "Transmission" },
    {
      "Title LIKE ?": "%On",
      "ArtistId > ?": 57,
    },
  ],
});
// This would effectively run the following query:
// "SELECT * FROM albums WHERE (Title = ?) OR (Title LIKE ? AND ArtisID > ?)"

Example 4: A join example with select and group by.

await query(db, {
  select: {
    "a.Name": "Name",
    "count(*)": "count",
  },
  from: "artists a join albums b on a.ArtistId = b.ArtistId",
  group_by: "a.ArtistId",
  having: { "count > ?": 12 },
});

update

Update the matching rows to the given values. Similar to other functions, update returns the affected rows.

Example:

await update(db, {
 table: "albums",
 where: { title: "Carry On" },
 set: { title: "Carry On!" },
});
// [{id: 1, title: "Carry On!"}]

remove

Remove one or more rows from a table, and returns the deleted rows.

Example 1: Deletes every row that matches the condition.

await remove(db, {
 from: "albums",
 where: { title: "Carry On" },
});
// [{id: 1, title: "Carry On"}]

More examples of the "where:" clause

Example 1: The keys are expressions and they reference the values by "?". Object keys are "AND"ed together.

 query({ ...,
   where: {
     name: "bob",
     "age > ?": 31,
   }
 })
 // { sql: "name = ? AND age > ?", values: ["bob", 31] }

Example 2: Arrays represent an "OR".

 query({ ...
   [
     {
       "name LIKE ?": "Frank%",
       "age > ?": 31,
     },
     { height: 181 },
   ]
 })
 // { sql: "(name = ? AND age > ?) OR (height = ?)", values: ["Frank%", 31, 181] }

Note that height: 31 is a shorthand for "height = ?": 31.