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

falsetto

v0.2.5

Published

Lightweight ODM for Apache Cassandra

Downloads

21

Readme

Falsetto - lightweight ODM for Apache Cassandra :rocket:

Build Status Coverage Status

Falsetto is a lightweight ODM layer on top of the cassandra-driver package, designed to make development with TS/JS as fast :rocket: as possible. Thank you for taking a look at the project, and if you feel this helped you in some way, please find out how you can contribute - we need all kinds of help :D

Start.

npm install falsetto

or with yarn:

yarn add falsetto

Create.

Let's use a humble User Schema as a beginning point, our schema has the following properties:

  • id - uuid
  • firstName - String
  • lastName - String
  • email - String

Let's create the Schema:

// create some attributes:

const id = new UuidAttribute("id");
const firstName = new TextAttribute("first_name");
const lastName = new TextAttribute("last_name");
const email = new TextAttribute("email");

// we then generate a schema
const UserSchema = new Schema("user", {
    id,
    firstName,
    lastName,
    email
});

This is just a conceptual model at this point, and wouldn't have any effect on our physical implementation of this schema. So we've deliberated and possibly discussed with our architect(if that architect is someone other than you :) ) that this is all the information we need to save for the user. After some investigation and experimentation, we have decided that our user object needs to use the following query patterns:

  • get user by id
  • get user by email

So, let's create those query patterns:

const QueryById = Table.from(UserSchema).by(id);

const QueryByEmail = Table.from(UserSchema).by(email);

Now we have our conceptual model done, let's create those tables:

// shoutout to the guys doing awesome work on cassandra-driver
const cassandra = require("cassandra-driver");

// create a client to issue queries on.
const client = new cassandra.Client({
    contactPoints: ['127.0.0.1'],
    localDataCenter: 'datacenter1',
    keyspace: 'ks1'
});

// Create those tables.
UserSchema
    .createTables()
    .execute(client)

This will result in the following create table queries:

CREATE TABLE user_by_id(
  id uuid,
  first_name text, 
  last_name text,
  PRIMARY KEY id
)

CREATE TABLE user_by_email(
  id uuid,
  first_name text, 
  last_name text,
  PRIMARY KEY email
)

Insert.

Let's save our first user:

  const id = uuid();
  const email = "[email protected]";
  const firstName = "John";
  const lastName = "Doe";

  UserSchema
        .put({ email, firstName, lastName, id })
        .execute(client);

and there we go! This will create a User record in both our user_by_id and user_by_email tables by batch statements.

Query.

We can query our tables in two ways: by the schema and by id:

// query by schema - please don't do this, this is a guess made using the queries, although it will work most of the time, 
// we don't want the proficiency of your system to be based on a guess :D 
const johnDoe = UserSchema
                      .get()
                      .where("id")
                      .equals("123")
                      .execute(client);

// query by table
const johnDoe = QueryByEmail
                        .get()
                        .where("email")
                        .equals("[email protected]")
                        .execute(client)

// if you want to only get a subset of information, let's say just the id and email: 
const johnDoeIdEmail = QueryById
                         .get(["id","email"])
                         .where(id)
                         .equals("123")
                         .execute(client)

Contributing

There is a lot that can be done to improve Falsetto, and we'd greatly appreciate it if you contributed, regardless of your skill level or where your skills lie. Whether it be documentation, error handling or feature adding, if you think that there is something that will be helpful, please submit a PR and we'll take a look, make changes(if any) and merge!