Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A new kind of database: event-based + computed props + full-stack reactive + solid business model #2

Open
brillout opened this issue Dec 25, 2021 · 1 comment

Comments

@brillout
Copy link
Owner

Someone shares an image on Facebook:

  1. Database saves event "User X shared image https://example.org/image.jpg".
  2. Facebook defined a computed prop that downloads the image and meta data.

Someone clicks on the like button of the image:

  1. Database saves event "User Y likes image".
  2. Facebook defined a computed prop "total amount of likes" (the computed prop is just a JavaScript function that runs Math.sum() over the array of "User like" events) => the databse automatically re-runs the computed prop function => the computed prop is automatically updated.
  3. Row-level permissions:
    // Read
    export async function read({ row, context }) {
      if (context.user.role === 'admin') {
        return true
      }
      if( row.rolesAllowed.includes('public')) {
        return true
      }
      // Forbidden
      return false
    }
    // Mutations
    export async function write({ row, rowBefore, context }) {
      if (row.authorId === context.user.id) {
        return true
      }
      // `rowBefore` is `null` if mutation is `INSERT`
      if (rowBefore === null) {
        return true
      }
      return false
    }
  4. The database has a built-in ORM with deep UI framework (React, Vue, ...) integrations.
    import { useDb } from '@new-kind-of-database/react'
    
    function Image({ id }) {
      // `useDb.findOne()` is a React Hook (=> works with Suspense parent loader component)
      const { src, totalLikes } = useDb.findOne(id, select: {
        src: true,
        // We mark `totalLikes` as reactive => when `totalLikes` changes, the ORM
        // automaticallly updates the component (using React's hook system)
        totalLikes: 'reactive'
      })
    
      return <>
        <img src="{src}" />
        <p>
          Number of likes: {totalLikes}
        </p>
      </>
    }
    Everything is done automaticallly, e.g. the database automaticallly creates a socket connection to the server in order to listen to the corresponding database updates.

This leads to many drastic DX improvement, especially for user-centric highly-reactive apps such as Twitter or Facebook.

Solid business model: offer a SaaS with all bell and whistles (automatic scale, automatic backup, etc.). That said it's of paramount importance to fully support self-hosted, and open sourcing the entire source code (include of the SaaS). We are not afraid of AWS doing a SaaS clone; users will prefer the original over the AWS copy-cat.

If you feel drawn to work on this, let me know. Also, I'm ok with you being the CEO and me only being the "master mind" behind the whole thing.

@trusktr
Copy link

trusktr commented Dec 26, 2021

cc @davedbase this is what we're were talking about with solid.js primitives

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants