simov / express-admin

MySQL, MariaDB, PostgreSQL, SQLite admin for Node.js
MIT License
1.17k stars 223 forks source link

Database View #77

Closed sidazhang closed 9 years ago

sidazhang commented 9 years ago

Hi,

I am only able to see tables in express-admin however, I am not able to see database views. Is there a way to enable views?

simov commented 9 years ago

Hi @sidazhang

I guess your question is about the custom views like this one If that's the case you can pull the examples repository and see how the custom views are configured there. Also take a look at the documentation

sidazhang commented 9 years ago

@simov, the question is actually simpler than a custom view!

It was asking about database view like this: http://www.postgresql.org/docs/8.3/static/tutorial-views.html

When reading, database views are basically the same as tables. And in custom.json, I also see that express-admin has pulled all the relevant database view datas. However, it is only rendering the tables.

Is there a way to render the views as well?

knownasilya commented 9 years ago

:+1: This would be very helpful!

simov commented 9 years ago

Ok, I got it. Marked this issue as a feature.

@sidazhang currently showing sql views is not supported. I'll make a few tests first to get an idea of how the code base should be updated.

sidazhang commented 9 years ago

@simov Thanks!

I am surprised that it doesn't support views (but then I am not familiar the code base :P ), since views is basically exactly the same as tables queries wise.

custom.json also already grabs the column information of the views as well!

simov commented 9 years ago

@sidazhang I think adding of readonly views will be relatively easy to implement. Non readonly views will require a bit more thinking, because the admin's listview and editview are designed for tables with primary key. As I'm understanding the views have specific requirements in order to update them, also obviously they don't have their own primary key. So do you have such views in your use case?

sidazhang commented 9 years ago

@simov My use case involves strictly readonly views.

Supporting readonly views would be an awesome feature :+1:

Thank you very much :)

simov commented 9 years ago

@sidazhang just pushed the fix. I still don't have tests for it, but in the meantime you can pull master and test it out with your views.

Here are the steps you can make, essentially that will be the test for readonly views:

  1. Start the admin
  2. In settings.json you have all views added as regular tables + they have one additional key "view":true

    "my_view": {
     "table":{
       ...
       "view": true
     }
    }
  3. All views are shown under the Views section in Mainview
  4. In Listview you have a filter and pagination for your views Here is what you can do to test it:
    • configure a filter for your view's listview and test out filtering
    • test out ordering
    • test out whether the pagination works correctly

Keep in mind that some of the settings options for regular tables won't work for views.

simov commented 9 years ago

https://github.com/simov/express-admin/releases/tag/1.2.5