GoPrisma - A Go wrapper for prisma to turn databases into GraphQL APIs using Go.

Overview

GoPrisma - a Go wrapper for the Prisma Engines

What's this?

Introspect a database and use it as a GraphQL API using Go.

Supported Databases:

  • SQLite
  • PostgreSQL
  • MySQL
  • MongoDB
  • MS SQL Server

go get

go get github.com/jensneuse/goprisma

Introspect a database

prismaSchema := "datasource db {provider = \"postgresql\" url = \"postgresql://admin:[email protected]:54321/example?schema=public&connection_limit=20&pool_timeout=5\"}"
schema, sdl, err := Introspect(prismaSchema)

Make a Query

query := "{\"query\": \"query Messages {findManymessages(take: 20 orderBy: [{id: desc}]){id message users {id name}}}","variables\": {}}"
engine, err := NewEngine(schema)
if err != nil {
	return
}
defer engine.Close()
response := engine.Execute(query)

Why?

GraphQL is a nice abstraction layer on top of other APIs. Making databases available can be a productivity gainer when no direct database access is required and GraphQL clients already exist in the codebase.

How does it work

Prisma is a really powerful ORM. If you look closely, you'll realize that internally, Prisma 2 is powered by a GraphQL Engine to abstract away the database layer.

The GraphQL Engine is written in Rust.

This library is a CGO wrapper to make the Prisma Rust GraphQL Engine available to write Go programs on top of it.

Is it fast?

I've measured ~0.3ms latency (Go -> Rust -> Database -> Go) on my laptop using a database in docker.

goos: darwin
goarch: amd64
pkg: github.com/jensneuse/goprisma/pkg/prisma
cpu: Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
BenchmarkEngine_Execute
BenchmarkEngine_Execute-16    	   43815	    304507 ns/op	     144 B/op	       3 allocs/op
PASS

You can find the benchmark in the prisma package tests and run it yourself.

What architectures are supported?

  • darwin x86_64
  • darwin aarch64
  • linux x86_64
  • windows x86_64 (needs verification)

Other targets can be added.

Where is the Rust wrapper?

https://github.com/jensneuse/prisma-engines/tree/goprisma

Example / How to run the tests?

First, clone the repo.

cd docker-example
docker-compose up

Now you're able to run the tests.

How can you help?

Testing

You can help by running the tests and architectures that need verification. Please report any issues and tell me if it works.

Automate building the C-Wrapper

You might want to increase the level of trust by adding a github action to automate building the Rust C-Wrapper. Currently, I'm building it on my MacBook.

Ideally, this github action would fetch the latest stable of prisma-engines, compile the C-Wrapper and updates the lib folder via PR. A blueprint how to do this can be found here: https://github.com/rogchap/v8go/blob/master/.github/workflows/v8build.yml

If you're interested in adding this, please open a PR.

Considerations

It might be obvious, but I just want to make it clear that you should NOT publicly expose your database with this library. This is only intended for use cases where the GraphQL API is shielded by some other component.

You might also like...
A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL

backend A REST web-service sample project written in Golang using go-fiber, GORM and PostgreSQL How to run Make sure you have Go installed (download).

Go WhatsApp REST API Implementation Using Fiber And Swagger
Go WhatsApp REST API Implementation Using Fiber And Swagger

Go WhatsApp REST API Implementation Using Fiber And Swagger Package cooljar/go-whatsapp-fiber Implements the WhatsApp Web API using Fiber web framewor

💫 API made in Go using MongoDB and JWT.

💫 Go MongoDB API 🎯 What is that API made in Go using MongoDB and JWT. 🔧 Features Not many libs & clean code JWT & MongoDB 3 routes (GET /token, GET

A Simple REST API Build Using Golang

gorestapi A Simple REST API Build Using Golang About gorestapi: a simple music restapi that retrives info about the author, album name, price of it ge

An example implementation of a REST interface in Golang using primarily the standard library.

REST API in Golang This is an example REST API implementation using primarily the standard library. The exceptions are as follows. github.com/gorilla/

REST API made using native Golang libraries. This API resembles the basic working of Instagram.
REST API made using native Golang libraries. This API resembles the basic working of Instagram.

Golang RESTful API for Instagram A Go based REST API built using native libraries. The API has been thoroughly worked through with Postman. Routes inc

Example Golang API backend rest implementation mini project Point Of Sale using Gin Framework and Gorm ORM Database.

Example Golang API backend rest implementation mini project Point Of Sale using Gin Framework and Gorm ORM Database.

A join table using a composite index with gorm and liquibase

Code to model checking in to events at kiosks. Context: A kiosk enables users to check in to one of several events. At the same time, multiple kiosks

A list of modules useful for using with fiber

Fiber Modules A list of modules useful for using with fiber Install go get github.com/gkampitakis/fiber-modules Contents healthcheck Local Development

Comments
  • go get failed

    go get failed

    Hey – this project is really exciting. I just gave it a go but unfortunately ran into the following error:

    go get github.com/jensneuse/goprisma/pkg/prisma
    
    go: downloading github.com/jensneuse/goprisma v0.0.0-20210531103550-6521fb3d61b3
    # github.com/jensneuse/goprisma/pkg/prisma
    ld: warning: ignoring file /Users/m/dev/pkg/mod/github.com/jensneuse/[email protected]/lib/darwin/libquery_engine_c_api.dylib, building for macOS-x86_64 but attempting to link with file built for unknown-unsupported file format ( 0x76 0x65 0x72 0x73 0x69 0x6F 0x6E 0x20 0x68 0x74 0x74 0x70 0x73 0x3A 0x2F 0x2F )
    Undefined symbols for architecture x86_64:
      "_free_introspection_result", referenced from:
          __cgo_2dba20b15c43_Cfunc_free_introspection_result in _x002.o
         (maybe you meant: __cgo_2dba20b15c43_Cfunc_free_introspection_result)
      "_free_prisma", referenced from:
          __cgo_2dba20b15c43_Cfunc_free_prisma in _x002.o
         (maybe you meant: __cgo_2dba20b15c43_Cfunc_free_prisma)
      "_prisma_execute", referenced from:
          __cgo_2dba20b15c43_Cfunc_prisma_execute in _x002.o
         (maybe you meant: __cgo_2dba20b15c43_Cfunc_prisma_execute)
      "_prisma_introspect", referenced from:
          __cgo_2dba20b15c43_Cfunc_prisma_introspect in _x002.o
         (maybe you meant: __cgo_2dba20b15c43_Cfunc_prisma_introspect)
      "_prisma_new", referenced from:
          __cgo_2dba20b15c43_Cfunc_prisma_new in _x002.o
         (maybe you meant: __cgo_2dba20b15c43_Cfunc_prisma_new)
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    
    go env
    GO111MODULE="on"
    GOARCH="amd64"
    GOBIN=""
    GOCACHE="/Users/m/Library/Caches/go-build"
    GOENV="/Users/m/Library/Application Support/go/env"
    GOEXE=""
    GOFLAGS=""
    GOHOSTARCH="amd64"
    GOHOSTOS="darwin"
    GOINSECURE=""
    GOMODCACHE="/Users/m/dev/pkg/mod"
    GONOPROXY=""
    GONOSUMDB=""
    GOOS="darwin"
    GOPATH="/Users/m/dev"
    GOPRIVATE=""
    GOPROXY="https://proxy.golang.org,direct"
    GOROOT="/usr/local/go"
    GOSUMDB="sum.golang.org"
    GOTMPDIR=""
    GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
    GOVCS=""
    GOVERSION="go1.16.3"
    GCCGO="gccgo"
    AR="ar"
    CC="clang"
    CXX="clang++"
    CGO_ENABLED="1"
    GOMOD="/Users/m/dev/src/github.com/matthewmueller/hack/go.mod"
    CGO_CFLAGS="-g -O2"
    CGO_CPPFLAGS=""
    CGO_CXXFLAGS="-g -O2"
    CGO_FFLAGS="-g -O2"
    CGO_LDFLAGS="-g -O2"
    PKG_CONFIG="pkg-config"
    GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/4f/tcxcr6_55v9bp38d8g4hjlf80000gn/T/go-build2413581743=/tmp/go-build -gno-record-gcc-switches -fno-common"
    

    Any ideas? Thanks!

    opened by matthewmueller 7
Releases(v0.1.0)
Owner
Jens Neuse
Jens Neuse
It is POC to create web apis using golang

Web API using golang It is POC to create web apis using golang. It is not using a good architecture like hexagonal archicture. But, it contains a CRUD

Wagner Marques 4 Aug 16, 2021
Bramble is a production-ready GraphQL federation gateway.

Bramble is a production-ready GraphQL federation gateway. It is built to be a simple, reliable and scalable way to aggregate GraphQL services together.

Movio 431 Sep 19, 2022
SendGrid's Golang HTTP Client for calling APIs

Quickly and easily access any RESTful or RESTful-like API. If you are looking for the SendGrid API client library, please see this repo. Announcements

Twilio SendGrid 161 Sep 25, 2022
Generate boilerplate + endpoints for Fiber REST APIs.

gomakeme Generate boilerplate + endpoints for Fiber REST APIs. Never spend 6 minutes doing something by hand when you can spend 1 week to automate it

null 4 May 9, 2022
⚓️ Golang RESTful APIs

Golang RESTful Golang RESTful API started on January 23rd, 2022. 环境配置相关解决办法

Hou Wenbo 0 Jan 23, 2022
The Direct Route GO SDK provides a thin wrapper around the Direct Route API for sending private transactions

Direct Route Go SDK The Direct Route GO SDK provides a thin wrapper around the D

null 26 Aug 14, 2022
Data injection wrapper for values maintained in a GCP Secret Manager document.

injector The injector is a utility that retrieves a GCP Secret Manager document which contains an HJSON or JSON object with an embedded top-level envi

Mark Eissler 0 Jan 19, 2022
REST api using fiber framework written in golang and using firebase ecosystem to authentication, storage and firestore as a db and use clean architecture as base

Backend API Example FiberGo Framework Docs : https://github.com/gofiber Info This application using firebase ecosystem Firebase Auth Cloud Storage Fir

Atilla Pehlivan 3 May 31, 2022
Web framework for creating apps using Go in Google AppEngine

Welcome to app.go v3.0 app.go is a simple web framework for use in Google AppEngine. Just copy the app folder to your working folder and import it fro

George Nava 46 Mar 21, 2021
package for building REST-style Web Services using Go

go-restful package for building REST-style Web Services using Google Go Code examples using v3 REST asks developers to use HTTP methods explicitly and

Ernest Micklei 4.6k Sep 30, 2022