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

@rawewhat/quera

v0.0.1

Published

QueRa is a simplified Firestore and GraphQL client built purely in React hooks.

Downloads

1

Readme

QueRa

is a simplified Firestore and GraphQL(soon) client built purely in React hooks.

Content

Install

using npm
npm i @rawewhat/quera

using yarn
yarn add @rawewhat/quera

Usage

  • just import useFirestore() hook in your React component.
import useFirestore from "@rawewhat/quera";
  • call useFirestore() hook to get subscribed data and CRUD handler functions
const [data, handler] = useFirestore(collectionPath, whereClause);
  • handlers include CRUD basic function like createDoc(), deleteDoc(), readDoc(), and updateDoc().
  • passing where clause to select only documents with specific value "?name == QueRa"

API

1. CRUD Operation

  • call useFirestore() hook to get CRUD handler functions.
const [, { createDoc, deleteDoc, readDoc, updateDoc }] = useFirestore();
  • NOTE
    without passing path to useFirestore(path) hook,
    all CRUD functions required collectionPath parameter!

1.1. createDoc(createData, collectionPath)

  • createData: object
  • collectionPath: string
createDoc({ name: "New Name" }, "user").then(doc => {
  console.log("doc.name =", doc.data.name);
});

const createdDoc = await createDoc({ name: "New Name" }, "user");
console.log("doc.name =", createdDoc.data.name);

Result: doc.name = New Name

1.2. deleteDoc(docId, collectionPath)

  • docId: string
  • collectionPath: string
deleteDoc("007", "user").then(doc => {
  console.log("doc 007", !doc.data ? "deleted" : "delete fail!");
});

const deletedDoc = await deleteDoc("007", "user");
console.log("doc 007", !deletedDoc.data ? "deleted" : "delete fail!");

Result: doc 007 deleted

1.3. readDoc(undefined, collectionPath)

  • passing undefined to get all documents in collection path
  • collectionPath: string
readDoc(undefined, "user").then(response => {
  response.data.forEach(doc => {
    console.log(`${doc.id}`, doc);
  });
});

const response = await readDoc(undefined, "user");
response.data.forEach(doc => {
  console.log(`doc ${doc.id} =`, doc);
});

Result: doc 007 = { name: New Name }

1.4. readDoc(docId, collectionPath)

  • docId: string
  • collectionPath: string
readDoc("007", "user").then(doc => {
  console.log("doc 007", doc);
});

const doc = await readDoc("007", "user");
console.log("doc 007 =", doc);

Result: doc 007 = { name: New Name }

1.5. readDoc(whereClause, collectionPath)

  • whereClause: string
  • collectionPath: string
readDoc("?name == New Name", "user").then(response => {
  response.data.forEach(doc => {
    console.log(`doc ${doc.id} =`, doc);
  });
});

const response = await readDoc("?name == New Name", "user");
response.data.forEach(doc => {
  console.log(`doc ${doc.id} =`, doc);
});

Result: doc 007 = { name: New Name }

1.6 updateDoc(docId, updateData, collectionPath)

  • docId: string
  • updateData: object
  • collectionPath: string
updateDoc('007', { name: 'Updated Name' }, 'user').then(doc => {
    console.log('doc 007 updated =', doc)
})

const updatedDoc = await updateDoc('007', { name: 'Updated Name' }, 'user')
console.log('doc 007 updated =', doc)

Result: doc 007 updated = { name: Updated Name }

2. Real-time Data Subscription

const [data, handlers] = useFirestore(collectionPath);
  • data: arrays

  • collectionPath: string

  • NOTE
    passing path to useFirestore(path) hook will subscribe component to the collection path,
    all CRUD functions will use collectionPath passed from useFirestore(path) hook. but you can still force to use collectionPath passing from CRUD function instead.

2.1 useFirestore(firestore, collectionPath)

  • firestore: object
  • collectionPath: string
const [data, handlers] = useFirestore(firestore, 'user')
console.log('subscribed data =', data)

2.2 useFirestore(firestore, collection_path, where_clause)

  • firestore: object
  • collectionPath: string
  • whereClause: string
const [data, handlers] = useFirestore(firestore, 'user', '?name == Updated Name')
console.log('subscribed data', data)

Example

import React, { useEffect } from "react";
import { useFirestore } from "@rawewhat/quera";

const _ = undefined;
const ID_TEST = "SbfOYDq77jG8N6v9N15k";
const CREATE_DATA_TEST = { name: "New Name" };

const HomeScreen = () => {
  const [{ data }, { createDoc, deleteDoc, readDoc, updateDoc }] = useFirestore(
    "delivery_telegram"
  );
  console.log("data", data);

  const handleClick = type => () => {
    switch (type) {
      case "create":
        return createDoc(CREATE_DATA_TEST, "delivery_telegram");
      case "delete":
        return deleteDoc(ID_TEST, "delivery_telegram");
      case "read":
        return readDoc(_, "delivery_telegram");
      case "read-by-id":
        return readDoc(ID_TEST, "delivery_telegram");
      case "read-by-query":
        return readDoc("?status == REQUESTED", "delivery_telegram");
      case "update":
        return updateDoc(ID_TEST, { status: "OPERATED" }, "delivery_telegram");
      case "update-requested":
        return updateDoc(ID_TEST, { status: "REQUESTED" }, "delivery_telegram");
      default:
    }
  };

  return (
    <div style={styles.container}>
      <h1>Test useFirestore</h1>
      <div style={styles.buttonContainer}>
        <h2>Create</h2>
        <Button title="Create" onClick={handleClick("create")} />
        <h2>Delete</h2>
        <Button title="Delete" onClick={handleClick("delete")} />
        <h2>Read</h2>
        <Button title="Read all doc" onClick={handleClick("read")} />
        <Button title="Read doc by id" onClick={handleClick("read-by-id")} />
        <Button
          title="Read doc by query"
          onClick={handleClick("read-by-query")}
        />
        <h2>Update</h2>
        <Button title="Update Operated" onClick={handleClick("update")} />
        <Button
          title="Update Requested"
          onClick={handleClick("update-requested")}
        />
      </div>
    </div>
  );
};

const Button = ({ title, children, onClick }) => {
  return (
    <button style={styles.button} onClick={onClick}>
      {children || title}
    </button>
  );
};

Demo

I wrote a simple site to test out QueRa functionality in the demo project.

  • git clone [email protected]:rawewhat/routra.git to clone the project
  • cd demo change to demo directory
  • yarn install to install dependencies
  • yarn dev it will be ready on http://localhost:1234

License

MIT License
-----------

Copyright (c) 2019 Cheng Sokdara (https://rawewhat-team.com)
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.