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

@godspeedsystems/plugins-prisma-as-datastore

v2.0.7

Published

Prisma as a datasource plugin for Godspeed Framework.

Downloads

145

Readme

godspeed-plugin-prisma-as-datasource

Welcome to the Godspeed Prisma Plugin! 🚀

"Prisma: Bridging Databases for Seamless Development. One Toolkit, Any Database."

Prisma is a modern and open-source database toolkit that simplifies database access for developers. It offers a strongly typed query builder, schema migrations, support for various databases, real-time data synchronization, and enhanced security, making it a powerful tool for efficient and secure database interactions in web applications.

How to Use

  • Create a godspeed project from the CLI , open the created project in vscode and then add the plugin from the CLI of vscode, select the @godspeedsystems/plugins-prisma-as-datastore to integrate the plugin.
> godspeed plugin add
       ,_,   ╔════════════════════════════════════╗
      (o,o)  ║        Welcome to Godspeed         ║
     ({___}) ║    World's First Meta Framework    ║
       " "   ╚════════════════════════════════════╝
? Please select godspeed plugin to install: (Press <space> to select, <Up and Down> to move rows)
┌──────┬────────────────────────────────────┬────────────────────────────────────────────────────────────────────┐
│      │ Name                               │ Description                                                        │
├──────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────┤
│ ❯◯   │ prisma-as-datastore                │ Prisma as a datasource plugin for Godspeed Framework.              │
├──────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────┤
│  ◯   │ aws-as-datasource                  │ aws as datasource plugin for Godspeed Framework                    │
├──────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────┤
│  ◯   │ excel-as-datasource                │ excel as datasource plugin for Godspeed Framework                  │
├──────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────┤
│  ◯   │ mailer-as-datasource               │ mailer as datasource plugin for Godspeed Framework                 │
├──────┼────────────────────────────────────┼────────────────────────────────────────────────────────────────────┤
│  ◯   │ kafka-as-datasource-as-eventsource │ kafka as datasource-as-eventsource plugin for Godspeed Framework   │
└──────┴────────────────────────────────────┴────────────────────────────────────────────────────────────────────┘
  • You will find the a file in your project related to the Prisma plugin at src/datasources/types/prisma.ts

prisma.ts

import { DataSource } from '@godspeedsystems/plugins-prisma-as-datastore';
export default DataSource;

Now create a Prisma file with your required database in <database_name.prisma> check below sample mongo.prisma file

Databases supported by Prisma

Prisma supports a variety of data sources, allowing you to connect to and work with different database systems. As of my last knowledge update in September 2021, Prisma supports the following data sources:

  1. PostgreSQL: Prisma has strong support for PostgreSQL, one of the most popular open-source relational database systems.

  2. MySQL: Prisma can be used with MySQL, another widely used open-source relational database management system.

  3. SQLite: SQLite is a serverless, self-contained, and zero-configuration database engine, and Prisma supports it as well.

  4. SQL Server: Prisma offers support for Microsoft SQL Server, a popular commercial relational database management system.

  5. MongoDB (Experimental): Prisma also has experimental support for MongoDB, a NoSQL database, although this support may not be as mature as for relational databases.

  6. CockroachDB: A distributed, resilient SQL database for large-scale, cloud-native applications.

  7. MariaDB: An open-source, high-performance relational database system and MySQL-compatible alternative.

  8. PlanetScale: PlanetScale is a database-as-a-service platform designed for distributed SQL databases. It provides a managed, scalable, and highly available database solution for modern, cloud-native applications.

Example prisma file using mongo database

mongo.prisma


datasource db {
  provider = "mongodb"
  url      = env("MONGO_TEST_URL") //Connection string can be found in the .env folder. you can add your own database connection string
}

generator client {
  provider        = "prisma-client-js"
  output          = "./prisma-clients/mongo"
  previewFeatures = ["metrics"]
}

model User {
  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  createdAt DateTime @default(now())
  email     String   @unique
  name      String?
  role      Role     @default(USER)
  posts     Post[]
}

model Post {
  id        String   @id @default(auto()) @map("_id") @db.ObjectId
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
  published Boolean  @default(false)
  title     String
  author    User?    @relation(fields: [authorId], references: [id])
  authorId  String   @db.ObjectId
}

enum Role {
  USER
  ADMIN
}

Create a prisma schema according to your selected database and save it,the above schema is created for mongo database

To learn more about prisma schema and it databases Checkout prisma

Open terminal in vscode and enter the below command

godspeed prisma prepare

This command will generate the prisma client and will sync the database with prisma schema

Now to generate the CRUD API'S enter the below command

godspeed gen-crud-api
  • This command will generate the crud apis based on the sample prisma schema provided at ./src/datasources/mongo.prisma

  • Now you can view the event and workflows according defined prisma schema

sample event for get api

http.get./mongo/post/{id}:
  summary: Fetch Post
  description: Fetch Post from database
  fn: com.biz.mongo.post.one
  params:
    - name: id
      in: path
      required: true
      schema:
        type: string
  responses:
    content:
      application/json:
        schema:
          type: object

sample workflow for get api

summary: Fetch Post
tasks:
  - id: mongo_post_one
    fn: datasource.mongo.Post.findUnique
    args:
      where:
        id: <% inputs.params.id %>

Run godspeed serve to start the development server.

godspeed serve

Thank You For Using Godspeed