Giter Club home page Giter Club logo

prostgles-server-js's Introduction

prostgles-server

Isomorphic PostgreSQL client for node

GitHub license npm version Tests

New: JSONB schema runtime validation and TS types

Features

  • CRUD operations
  • Subscriptions to data changes
  • Fine grained access control
  • Optimistic data replication
  • Generated TypeScript Definition for Database schema

Installation

$ npm install prostgles-server

Quick start

let prostgles = require('prostgles-server');

prostgles({
  dbConnection: {
    host: "localhost",
    port: "5432",
    user: process.env.PG_USER,
    password: process.env.PG_PASS
  },
  onReady: async ({ dbo }) => {
  
    const posts = await dbo.posts.find(
      { title: { $ilike: "%car%" } }, 
      { 
        orderBy: { created: -1 }, 
        limit: 10 
      }
    );
    
  }
});

Server-Client usage

server.js

const express = require('express');
const app = express();
const path = require('path');
var http = require('http').createServer(app);
var io = require('socket.io')(http);
http.listen(3000);

let prostgles = require('prostgles-server');

prostgles({
  dbConnection: {
    host: "localhost",
    port: "5432",
    user: process.env.PRGL_USER,
    password: process.env.PRGL_PWD
  },
  io,
  publish: "*", // Unrestricted INSERT/SELECT/UPDATE/DELETE access to the tables in the database
  onReady: async (dbo) => {
    
  }
});

react.tsx

const App = () => {
  const { isLoading, dbo } = useProstglesClient();
  if(isLoading) return null;
  return <>
    Database tables: {Object.keys(dbo)}
  </>
}

./public/index.html

 
<!DOCTYPE html>
<html>
  <head>
   <title> Prostgles </title>
   
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://unpkg.com/socket.io-client@latest/dist/socket.io.min.js" type="text/javascript"></script>
    <script src="https://unpkg.com/prostgles-client@latest/dist/index.js" type="text/javascript"></script>	
  </head>
  <body>

    <script>

      prostgles({
        socket: io(), 
        onReady: async ({ dbo, dbsMethods, schemaTables, auth }) => {

        }
      });

    </script>
    
  </body>
</html>

License

MIT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.