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

rethinkdb-ts-extra

v0.3.0

Published

rethinkdb-ts with extra utilities for typing and structure syncing

Downloads

60

Readme

rethinkdb-ts-extra

This package is an extension of rethinkdb-ts and functions as an almost drop-in replacement. Everything from rethinkdb-ts is re-exported (except r itself).

The overall purpose of this package is to configure strictly typed data structures (and secondary indexes) for every table in your database. This provides numerous advantages and makes it (generally) safer to work with your data. It also corrects some small inconsistencies/bugs in the original typings for rethinkdb-ts.

Installation & Usage

# Install from npm (or pnpm, bun, yarn, etc)
npm i rethinkdb-ts-extra

If you're using rethinkdb-ts or another package already, you can safely remove that from your dependencies.

From here, check out the wiki and Getting Started page for more detailed documentation, examples, and explanations.

Example

import { extra, table } from 'rethinkdb-ts-extra'

// definitions
interface User {
  id: string
  username: string
}

interface Post {
  id: string,
  author_id: string,
  tags: string[]
}

/* etc... you would define interfaces/types for everything in your database,
  which I put in other files */

const r = await extra({
  // describe database layout/structure/data types/indexes/etc
  my_database: {
    users: table<User>()({ /* indexes would go here, but we have none for users */ }),
    posts: table<Post>()({
      author_id: {}, // simple index
      tags: { multi: true }, // multi index
      /* (a 'url' index like this is a bit silly but it's just to demonstrate custom expression indexes) */
      url: { custom: function (post) { return r.add('/', post('author_id'), '/', post('id')) } }
    })
  }
}, {
  // immediately connect
  url: process.env.RETHINKDB_URL, // connection URLs
  db: 'my_database' // default db
}, {
  // automatically 'sync' the database to match the configurations
  dropUnknownIndexes: true,
  log: 'verbose'
})

// export to use everywhere else in the project
export const { r }

// and then...
const posts = await r.table('posts').getAll('ben', { index: 'author_id' }).run()
console.log(posts) // Post[]

Project Status

You (probably) shouldn't find any functionality issues in this project, since it's all pretty straight forward. You may find typing issues.

I built this internally for a private project and have pulled it out to open source. Everything works fine within the scope of my project, but I don't do everything with RethinkDB and it's definitely possible that you could encounter something weird with typings that I haven't, in which case please make an issue!