-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(prisma): upgrade prisma to v5.19.0 (#1331)
* chore(prisma): upgrade prisma to v5.18.0 * adapt to new raw queries * 5.19.0
- Loading branch information
Showing
5 changed files
with
42 additions
and
164 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
package binaries | ||
|
||
// PrismaVersion is a hardcoded version of the Prisma CLI. | ||
const PrismaVersion = "5.16.2" | ||
const PrismaVersion = "5.19.0" | ||
|
||
// EngineVersion is a hardcoded version of the Prisma Engine. | ||
// The versions can be found under https://github.com/prisma/prisma-engines/commits/main | ||
const EngineVersion = "34ace0eb2704183d2c05b60b52fba5c43c13f303" | ||
const EngineVersion = "5fe21811a6ba0b952a3bc71400666511fe3b902f" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,43 @@ | ||
package engine | ||
|
||
import ( | ||
"encoding/base64" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/steebchen/prisma-client-go/logger" | ||
"strings" | ||
) | ||
|
||
// transformResponse for raw queries | ||
// transforms all custom prisma types into native go types, such as | ||
// [{"prisma__type":"string","prisma__value":"asdf"},{"prisma__type":"null","prisma__value":null}] | ||
// -> | ||
// ["asdf", null] | ||
func transformResponse(data []byte) ([]byte, error) { | ||
var m interface{} | ||
if err := json.Unmarshal(data, &m); err != nil { | ||
return nil, err | ||
} | ||
type Input struct { | ||
Columns []string `json:"columns"` | ||
Types []string `json:"types"` | ||
Rows [][]interface{} `json:"rows"` | ||
} | ||
|
||
forEachValue(&m, func(k *string, i *int, v *interface{}) (interface{}, bool) { | ||
if v == nil { | ||
return nil, false | ||
} | ||
var n = *v | ||
o, isObject := (*v).(map[string]interface{}) | ||
if isObject { | ||
var ok bool | ||
n, ok = handleObject(o) | ||
if !ok { | ||
return n, false | ||
} | ||
} | ||
return n, true | ||
}) | ||
// TransformResponse for raw queries | ||
func TransformResponse(data []byte) ([]byte, error) { | ||
// TODO properly detect a json response | ||
if !strings.HasPrefix(string(data), `{"columns":[`) { | ||
return data, nil | ||
} | ||
|
||
out, err := json.Marshal(m) | ||
var input Input | ||
err := json.Unmarshal(data, &input) | ||
if err != nil { | ||
return nil, fmt.Errorf("transform response marshal: %w", err) | ||
return nil, err | ||
} | ||
|
||
logger.Debug.Printf("transformed response: %s", out) | ||
|
||
return out, nil | ||
} | ||
output := make([]map[string]interface{}, 0) | ||
|
||
func handleObject(o map[string]interface{}) (interface{}, bool) { | ||
if t, ok := o["prisma__type"]; ok { | ||
if t == "bytes" { | ||
// bytes from prisma are base64 encoded | ||
bytes, ok := o["prisma__value"].(string) | ||
if !ok { | ||
panic("expected bytes") | ||
} | ||
dst := make([]byte, base64.StdEncoding.DecodedLen(len(bytes))) | ||
n, err := base64.StdEncoding.Decode(dst, []byte(bytes)) | ||
if err != nil { | ||
panic(err) | ||
} | ||
dst = dst[:n] | ||
return dst, false | ||
for _, row := range input.Rows { | ||
m := make(map[string]interface{}) | ||
for i, column := range input.Columns { | ||
m[column] = row[i] | ||
} | ||
if t == "array" { | ||
value, ok := o["prisma__value"].([]interface{}) | ||
if !ok { | ||
panic("expected array") | ||
} | ||
var items []interface{} | ||
for _, item := range value { | ||
item, _ := handleObject(item.(map[string]interface{})) | ||
items = append(items, item) | ||
} | ||
return items, false | ||
} | ||
return o["prisma__value"], false | ||
output = append(output, m) | ||
} | ||
return o, true | ||
} | ||
|
||
func forEachValue(obj *interface{}, handler func(*string, *int, *interface{}) (interface{}, bool)) { | ||
if obj == nil { | ||
return | ||
} | ||
var ok bool | ||
var n = *obj | ||
// Yield all key/value pairs for objects. | ||
o, isObject := (*obj).(map[string]interface{}) | ||
if isObject { | ||
for k := range o { | ||
item := o[k] | ||
o[k], ok = handler(&k, nil, &item) | ||
item = o[k] | ||
if ok { | ||
forEachValue(&item, handler) | ||
} | ||
} | ||
n = o | ||
} | ||
// Yield each index/value for arrays. | ||
a, isArray := (*obj).([]interface{}) | ||
if isArray { | ||
for i := range a { | ||
item := a[i] | ||
a[i], ok = handler(nil, &i, &item) | ||
item = a[i] | ||
if ok { | ||
forEachValue(&item, handler) | ||
} | ||
} | ||
n = a | ||
o, err := json.Marshal(output) | ||
if err != nil { | ||
return nil, err | ||
} | ||
*obj = n | ||
// Do nothing for primitives since the handler got them. | ||
|
||
return o, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters