Comments (7)
Issue was related to https://github.com/apuigsech/rest-layer-sql/blob/master/query.go#L222
it uses LIKE
operator to compare the id, so for string works but with uuid type it doesn't, I had to clone the repo and add my own customization
from rest-layer.
Nice that you where able to solved it.
You may consider raising a bug against reset-layer-sql
. Using LIKE
does not sound like something you would want to do for an ID comparison...
from rest-layer.
Hi. We need more information in order to help you. It could be this is an issue with rest-layer, or it can be an issue with the third-party storer implementation.
-
Which Storer implementation are you using?
-
How does you schema look like (or the ID field?
from rest-layer.
Hi @smyrman
- https://github.com/apuigsech/rest-layer-sql with https://github.com/lib/pq
- this is a fragment of the code implementation
// I have the server struct data
type Server struct {
httpAddress string
router *chi.Mux
db *sql.DB
shutdownTimeout time.Duration
}
index := resource.NewIndex()
// using sqlStorage "github.com/apuigsech/rest-layer-sql"
// s.db is server.db of type
h := sqlStorage.NewHandlerWithDB("postgres", s.db, "accounts", nil)
index.Bind("accounts", domain.Account, h, resource.Conf{
AllowedModes: resource.ReadWrite,
})
api, err := rest.NewHandler(index)
if err != nil {
log.Fatalf("Invalid API configuration: %s", err)
}
s.router.Mount("/api", http.StripPrefix("/api", api))
/// THE SCHEMA FOR ACCOUNT IS
var Account = schema.Schema{
Description: "Accounts schemas",
Fields: schema.Fields{
"id": {
Required: true,
Filterable: true,
Sortable: true,
},
"identifier": {
Required: true,
Filterable: false,
Sortable: false,
},
"password": {
Required: true,
Filterable: false,
Sortable: false,
},
},
}
// in postgres i created this table
create table if not exists accounts
(
id uuid not null,
etag varchar(128),
corporate_account boolean not null default false,
identifier varchar(250) not null unique,
password varchar(250) not null,
last_login timestamptz,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now(),
primary key (id)
);
from rest-layer.
You can try to add a schema.FieldValidator
to the ID field that converts an input of type string
to an uuid.ID
on Validate
, and if needed, from an uuid.ID
to string
on Serialize
.
This may help because the query preparation in rest-layer will run the field validator on relevant fields before running the query.
from rest-layer.
You can use which ever uuid
library that implements the relevant interfaces to convert from/to an SQL value.
from rest-layer.
You can try to add a
schema.FieldValidator
to the ID field that converts an input of typestring
to anuuid.ID
onValidate
, and if needed, from anuuid.ID
tostring
onSerialize
.This may help because the query preparation in rest-layer will run the field validator on relevant fields before running the query.
I created the validator with
type UUID struct {}
func (u UUID) Validate(value interface{}) (interface{}, error) {
s, ok := value.(string)
if !ok {
if b, ok := value.([]byte); ok {
id, error := identifier.Validate(string(b))
if error != nil {
return nil, error
}
return id.ID(), nil
}
return "", identifier.ErrInvalidUUID
}
id, error := identifier.Validate(s)
if error != nil {
return nil, error
}
return id.ID(), nil
}
But now POST actions is not working
{
"code": 520,
"message": "pq: invalid input syntax for type uuid: \"452129999\""
}
If I change id.String()
instead of id.ID()
the POST action is working, but UPDATE is not working is showing the same error
from rest-layer.
Related Issues (20)
- Remove old sub-resource syntax HOT 4
- go module: cannot find module providing package testing/mem HOT 3
- Explicit $eq in filter passes whole predicate to Validate(Query) HOT 3
- OnInsert/OnUpdate hooks can modify the new resource item, Etag not recalculated HOT 7
- `Prefer: return=minimal` can hide resource item on server modification HOT 12
- Consistent empty / null fields HOT 4
- Remove resource hooks in favor of resource middleware HOT 12
- Newest `zerolog` versions cause a panic HOT 4
- Bogus error line, when returning empty response on 204
- Etag should not depend on external state HOT 4
- Assist AutoIncrement FieldValidator with SQL backend HOT 8
- How use schema and resource package as standalone HOT 1
- Bulk PATCH support HOT 5
- Wrapping original issue in rest.Error HOT 7
- Feature Request: Cursor-based Pagination HOT 3
- Filter on reference fields HOT 1
- Support for $not filter operation HOT 4
- Decouple ElemMatch from schema.Array struct
- openapi 3.1.0 support HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rest-layer.