Support > Repository > Model definition > Use database view
ja | en

"View" prepared in the database can be treated as "Wagby" model.

It is possible to make reference to the view prepared in the database without creating the physical table of the model defined by Wagby.

Figure 1 Refer to view

The setting method is as follows.

  1. First,Setting not to create tablewill do.
  2. continue,Specify the view name as the physical table nameTo do.(It can be omitted if model name and view name are the same.)

Main key handling

Even when using views, you need a primary key.(Wagby's model must specify primary key.)

If there is no primary key in the view of the existing database, please add it.

Cache handling

Periodically clear Wagby cache information

For views with updates,Disable cachingcan do.However, disabling the cache will affect performance.When the update frequency is low,I use the cache, but use the job to periodically clear the cache informationPlease also consider methods such as.

Use materialized view

There is also a way to use "materialized view" provided by the database, while invalidating Wagby's cache.[Wikipedia...]

The materialized view is cached on the database side and the cache is also updated each time the original table is modified.So you can get the latest data.

If you are a database that can use materialized views, please consider using this.

You can use group privileges provided by Wagby by preparing the following on the view side (of the database to use).

  • Useridjshparam column.
  • (View name) $ jgroupidjshparam table.

The useridjshparam column adds "useridjshparam" to the SELECT clause of the view to be prepared and returns the data owner account.
(View name) In the $ jgroupidjshparam table, store the group ID of the group to which the data belongs.The group ID uses the primary key jgroupid of the jgroup table.

It is advisable to use xxxx $ jgroupidjshparam table in another model and refer to this.
(View name) You can also prepare the $ jgroupidjshparam table as a view, not actually a table.
The group authority controls browsing/updating by specifying the narrowing condition in the WHERE clause.Since the narrowing part of the WHERE clause is automatically generated by the Wagby side, it works by preparing the useridjshparam column and xxxx $ jgroupidjshparam.

Handling of mandatory items

In the model defined by Wagby as "Required", please check whether NULL actually exists on the view side.Since Wagby assumes that NULL does not exist in essential items, if NULL is found, data can not be acquired correctly and an error will result.