Coder Social home page Coder Social logo

tpdewolf / prisma Goto Github PK

View Code? Open in Web Editor NEW

This project forked from prisma/prisma1

0.0 0.0 0.0 188.88 MB

๐Ÿ’พ Database Tools incl. ORM, Migrations and Admin UI (Postgres, MySQL & MongoDB)

Home Page: https://www.prisma.io

License: Apache License 2.0

Shell 0.39% JavaScript 0.13% TypeScript 25.26% TSQL 4.97% HTML 0.20% Makefile 0.07% Scala 58.63% Java 0.36% Rust 9.97% C 0.03%

prisma's Introduction

Prisma

Website โ€ข Docs โ€ข Examples โ€ข Blog โ€ข Slack โ€ข Twitter โ€ข Prisma 2 (Preview)

CircleCI Slack Status Join the community on Spectrum

Prisma replaces traditional ORMs and simplifies database workflows:

  • Access: Type-safe database access with the auto-generated Prisma client (in JavaScript, TypeScript, Go)
  • Migrate: Declarative data modelling and migrations (optional)
  • Manage: Visual data management with Prisma Admin

It is used to build GraphQL, REST, gRPC APIs and more. Prisma currently supports MySQL, PostgreSQL, MongoDB.

Try a Prisma example online with CodeSandbox:

Prisma Client Demo GraphQL API REST API

Contents

Quickstart

Get started with Prisma from scratch (or use your existing database):

1. Install Prisma via Homebrew

brew tap prisma/prisma
brew install prisma
Alternative: Install with NPM or Yarn
npm install -g prisma
# or
yarn global add prisma

2. Connect Prisma to a database

To setup Prisma, you need to have Docker installed. Run the following command to get started with Prisma:

prisma init hello-world

The interactive CLI wizard now helps you with the required setup:

  • Select Create new database (you can also use an existing database or a hosted demo database)
  • Select the database type: MySQL or PostgreSQL
  • Select the language for the generated Prisma client: TypeScript, Flow, JavaScript or Go

Once the wizard has terminated, run the following commands to setup Prisma:

cd hello-world
docker-compose up -d

3. Define your datamodel

Edit datamodel.prisma to define your datamodel using SDL syntax. Each model is mapped to a table in your database schema:

type User {
  id: ID! @id
  email: String @unique
  name: String!
  posts: [Post!]!
}

type Post {
  id: ID! @id
  title: String!
  published: Boolean! @default(value: false)
  author: User
}

4. Deploy datamodel & migrate database

To deploy your Prisma API, run the following command:

prisma deploy

The Prisma API is deployed based on the datamodel and exposes CRUD & realtime operations for each model in that file.

5. Use the Prisma client (Node.js)

The Prisma client connects to the Prisma API and lets you perform read and write operations against your database. This section explains how to use the Prisma client from Node.js.

Inside the hello-world directory, install the prisma-client-lib dependency:

npm install --save prisma-client-lib

To generate the Prisma client, run the following command:

prisma generate

Create a new Node script inside the hello-world directory:

touch index.js

Add the following code to it:

const { prisma } = require('./generated/prisma-client')

// A `main` function so that we can use async/await
async function main() {
  // Create a new user with a new post
  const newUser = await prisma.createUser({
    name: 'Alice',
    posts: {
      create: { title: 'The data layer for modern apps' }
    }
  })
  console.log(`Created new user: ${newUser.name} (ID: ${newUser.id})`)

  // Read all users from the database and print them to the console
  const allUsers = await prisma.users()
  console.log(allUsers)

  // Read all posts from the database and print them to the console
  const allPosts = await prisma.posts()
  console.log(allPosts)
}

main().catch(e => console.error(e))

Finally, run the code using the following command:

node index.js
See more API operations

const usersCalledAlice = await prisma
  .users({
    where: {
      name: "Alice"
    }
  })
// replace the __USER_ID__ placeholder with an actual user ID
const updatedUser = await prisma
  .updateUser({
    where: { id: "__USER_ID__" },
    data: { email: "[email protected]" }
  })
// replace the __USER_ID__ placeholder with an actual user ID
const deletedUser = await prisma
  .deleteUser({ id: "__USER_ID__" })
const postsByAuthor = await prisma
  .user({ email: "[email protected]" })
  .posts()

6. Next steps

Here is what you can do next:

Examples

TypeScript

Demo Description
script Simple usage of Prisma client in script
graphql Simple GraphQL server based on graphql-yoga
graphql-apollo-server Simple GraphQL server based on apollo-server
graphql-crud GraphQL server with full CRUD API
graphql-auth GraphQL server with email-password authentication & permissions
graphql-subscriptions GraphQL server with realtime subscriptions
rest-express Simple REST API with Express.JS
grpc Simple gRPC API
docker-mongodb Set up Prisma locally with MongoDB
docker-mysql Set up Prisma locally with MySQL
docker-postgres Set up Prisma locally with PostgreSQL
cli-app Simple CLI TODO list app

Node.js

Demo Description
script Simple usage of Prisma client in script
graphql Simple GraphQL server
graphql-auth GraphQL server with email-password authentication & permissions
graphql-subscriptions GraphQL server with realtime subscriptions
rest-express Simple REST API with Express.JS
grpc Simple gRPC API
docker-mongodb Set up Prisma locally with MongoDB
docker-mysql Set up Prisma locally with MySQL
docker-postgres Set up Prisma locally with PostgreSQL
cli-app Simple CLI TODO list app

Golang

Demo Description
cli-app Simple CLI TODO list app
graphql Simple GraphQL server
http-mux Simple REST API with gorilla/mux
rest-gin Simple REST API with Gin
script Simple usage of Prisma client in script

Flow

Demo Description
graphql Simple GraphQL server
script Simple usage of Prisma client in script

Database Connectors

Database connectors provide the link between Prisma and the underlying database.

You can connect the following databases to Prisma already:

  • MySQL
  • PostgreSQL
  • MongoDB

Upcoming Connectors

If you are interested to participate in the preview for one of the following connectors, please reach out in our Slack.

Join the discussion or contribute to influence which we'll work on next!

Community

Prisma has a community of thousands of amazing developers and contributors. Welcome, please join us! ๐Ÿ‘‹

Meet the Prisma community in person and learn about modern application development and database best practices at Prisma Day (Berlin, June 19).

Channels

Resources

Contributing

Contributions are welcome and extremely helpful ๐Ÿ™Œ Please refer to the contribution guide for more information.

Releases are separated into three channels: alpha, beta and stable. You can learn more about these three channels and Prisma's release process here.

Prisma

Prisma 2 Preview

Prisma 2 splits up Prisma's core functionality into 2 standalone tools:

  • Photon: Type-safe database access
  • Lift: Declarative data modeling and migrations

Photon and Lift are currently in Preview! Limitations include missing features, limited performance and stability issues. You can learn more about Prisma 2 in the announcement or the docs.

You can track the progress of Prisma 2 on isprisma2ready.com.

prisma's People

Contributors

abhiaiyer91 avatar akoenig avatar c-riq avatar captdaylight avatar christiannwamba avatar cjoudrey avatar devanb avatar do4gr avatar dominikh avatar dpetrick avatar ejoebstl avatar etelsv avatar johannpinson avatar kbrandwijk avatar kuldar avatar maartennnn avatar marktani avatar maticzav avatar mavilein avatar nikolasburk avatar pancrisp avatar pantharshit00 avatar pimeys avatar qucode1 avatar schickling avatar sorenbs avatar spacekookie avatar timsuchanek avatar willm78 avatar yckao avatar

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.