Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot filter /schema/objects endpoint #456

Closed
MichalisDBA opened this issue Apr 11, 2024 · 24 comments
Closed

Cannot filter /schema/objects endpoint #456

MichalisDBA opened this issue Apr 11, 2024 · 24 comments
Assignees
Labels
enhancement New feature or request fixed-waiting-feedback Issue resolved pending final review.
Milestone

Comments

@MichalisDBA
Copy link

Can not filter /schema/objects endpoint to search for specific schemas, tables, views.

/schema/objects?filter=schema==
/schema/objects?filter=name==
/schema/objects?filter=type==

@thadguidry
Copy link
Collaborator

thadguidry commented Apr 11, 2024

Hi @MichalisDBA is this where you want to expose schema objects in your application? Was this so you can expose in a selector some categories or particular domains to your app users? Or did you have some other uses in mind of schema selection in your application you are building with DB2Rest?

Learning more about your use cases will help us understand better and perhaps come up with more logical filtering mechanisms to expose schema objects when the db user configured has those rights.

@MichalisDBA
Copy link
Author

Hi @thadguidry maybe would be better to be configurabled via env variables the schema/objects path.
My use case is to see what objects are loaded and available to me so i can query them.

That way i can give a user a single endpoint that he can see what objects are available to him to query instead of maintaining a list for every user of what he can query.

@thadguidry
Copy link
Collaborator

thadguidry commented Apr 11, 2024

Righto. OK. Hmm, isn't there a nice custom SQL expression to use instead for this with Oracle where you can query the USER_OBJECTS view? I know I can do this easily in PostgreSQL.
Sorry, but I've long forgotten my Oracle skills and the differences between stupid things like local user and common user etc.

Regardless, this https://docs.oracle.com/en/database/oracle/oracle-database/23/admin/managing-schema-objects.html#GUID-827749E0-E67C-44DB-ABA4-2596167F2EAE in section 17.13 does seem to resonate with this issue. Perhaps custom query to return ALL_OBJECTS or USER_OBJECTS views?

Let me know.

@thadguidry
Copy link
Collaborator

We "could" in theory more easily expose this through the API via something that might look like:

http://localhost:8080/?objectsOwned
http://localhost:8080/?objectsAll

or maybe /user?objectsOwned ? Wait NO, that syntax would be asking for the user table and a query parameter ... hmm. We need to come up with some good syntax for doing schema queries easily, while keeping our /<table>? convention. Maybe some keyword before the / ? or special parameter keywords directly after the / as my examples above?

@dhrubo ?

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

JDBC meta data builder queries these tables under the hood. Because the driver is implemented by the database vendor.

We rely on the metadata to provide the endpoint.Essentially it serves from the schema cache.

We can add the filters to this endpoint. Should be easy as the type of object is also in the cache.

@MichalisDBA
Copy link
Author

Sorry i think you misunderstand me. I am talking about the objects that are cached when you start db2rest.

db2rest introduced an /schema/objects endpoint that you can view all the objects that are cached from the application. You do not need to query the database system tables. Just the filtering does not work.

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

Will add filters in 0.2.9 😁

@thadguidry
Copy link
Collaborator

thadguidry commented Apr 11, 2024

well, the problem with that endpoint is that...

  • In PostgreSQL and others, you can actually have a table name called "schema". So that endpoint convention sorta breaks/rubs against our existing table syntax convention. You cannot have objects prefixed with pg_ however as they are reserved for system schemas. DB's have lots of reserved object names and differ by vendor.

@kdhrubo Not so sure about an endpoint named like that?

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

If a table named schema is present in user schema it will be cached and returned by this query.

@thadguidry
Copy link
Collaborator

Huh? So confused. Then how do I tell it the difference between...

  1. http://localhost:8080/schema <- my user created table named "schema" that holds some stupid video movies
  2. http://localhost:8080/schema <- what JDBC meta data builder exposes, which under the hood, I assume it would do this:
SELECT * FROM information_schema.role_table_grants WHERE grantee = 'YOUR_USER';

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

This endpoint ends with /objects so the MVC controller will use this one when the query is for db objects

When you want to view the records of the schema table then that endpoint does not end with /objects. This is how we can differentiate. Similar to the join syntax.

I am not sure what query the JDBC driver actually runs under the hood.

@thadguidry
Copy link
Collaborator

@kdhrubo I understand that. But that's like saying your sub-collection is dictating the actual real collection. But I am saying that it is not the way to do it properly at all. It actually breaks the REST best practices with Nesting to show Relationships between Sub-collection Resources, as well as noun pluralization for Collection Resources.

/posts/author
/posts/postId/comments
/schema
/schemas
/schemas/objects

We are doing it Non-RESTful then.
https://restfulapi.net/resource-naming/
https://www.javaguides.net/2018/06/restful-api-design-best-practices.html

And I don't really like that or appreciate that we break many RESTful best practices.

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

Not really it's very common to use command or controller pattern for such scenarios.

If you can suggest a better name for this end point we can make changes.

@thadguidry
Copy link
Collaborator

thadguidry commented Apr 11, 2024

It's very common that 1000's of developers do it WRONG. I absolutely know that. It's a common misunderstanding that gets abused in command and controller patterns because of lack of knowledge of RESTful Collection Naming conventions. We're the experts here and should stick to correct conventions of industry norms.

I'd suggest that we stick to our original plan of the first Collection to always be the <table name> resource.
I'd further suggest that when we don't care about dealing with Tables as the first Collection default resource, but instead system commands, that we can adopt a prefix convention such as $:

http://localhost:8080/$schema
http://localhost:8080/$version
http://localhost:8080/$help
etc...

This is like saying, give me the resource document for schema, version, help, etc.
When there is no document prefix, then we treat that first Collection resource as a <table name>

Google does this sorta thing for their API's, for example, play around

https://eventarc.googleapis.com/$discovery/rest?version=v1
https://eventarc.googleapis.com/$discovery

Btw, even JSON fields (keys) can use prefix conventions for various reasons:

"response": {
  "$ref": "GoogleLongrunningOperation"
}

When a <table name> resource literally named $myTable then we ask for quoted table names.
https://localhost:8080/"$myTable"

The URL https://localhost:8080/"$myTable" needs to be properly encoded for use in web requests. Let’s break it down:

Original URL: https://localhost:8080/"$myTable"
URI Encoding:
The $ character should be encoded as %24.
The double quotes (") should be encoded as %22.
Encoded URL: https://localhost:8080/%22%24myTable%22
Now you can use the encoded URL in your web requests! 😊

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 11, 2024

Makes sense..we can adopt the $ pattern.

Can you pls review the join syntax and recommend there (a separate issue please) 🥺

@kdhrubo kdhrubo self-assigned this Apr 13, 2024
@kdhrubo kdhrubo added the enhancement New feature or request label Apr 13, 2024
@kdhrubo kdhrubo added this to the April2024 milestone Apr 13, 2024
@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

image

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

image

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

Filter by schema name (like search on schema cache)

image

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

image

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

Search by type = table

image

Search by type = view

image

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 13, 2024

Will be available in 0.2.9 release

kdhrubo pushed a commit that referenced this issue Apr 13, 2024
@kdhrubo kdhrubo added the fixed-waiting-feedback Issue resolved pending final review. label Apr 13, 2024
kdhrubo added a commit that referenced this issue Apr 13, 2024
@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 20, 2024

@MichalisDBA - please share your feedback on this issue. let us know if it can be closed.

@MichalisDBA
Copy link
Author

@kdhrubo

Yes it is working fine. Just mentioned in the docs that to search for a table you have to use $schemas?filter=name==search and not use =like= operator.

@kdhrubo
Copy link
Collaborator

kdhrubo commented Apr 24, 2024

Closing follow up here -
9tigerio/db2rest-web#45

@kdhrubo kdhrubo closed this as completed Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed-waiting-feedback Issue resolved pending final review.
Projects
None yet
Development

No branches or pull requests

3 participants