Storing Business Logic in Database

后端 未结 11 1415
感情败类
感情败类 2021-01-30 00:04

We want to write some business logic rules that work on top of certain data to build reports. Not sure which is the best to store them in the database MySQL.

11条回答
  •  隐瞒了意图╮
    2021-01-30 00:27

    So if I understand correctly you are looking to use the front end to allow people to dynamically create logic that will be applied to queries (dynamically built where clauses at runtime based on which rules are being used)?

    If that is the case, you would need to be fairly specific about what conditions they can select in their rules (change in what value (column) so they can only have conditional rules against columns that exist in the dataset you are reporting from).

    If I am understanding your question correctly, I would start by mapping out which tables/columns you want them to be able to select conditions against. This will be your controls for the webpage to design the rules.

    However if you are just asking how to store the rules once they are chosen in the database, I would suggest storing it in a single table that contains:

    ID  |  RuleSetName         |  Table     |  Column      |  Comparison  |  Value   |  Percentage  |  Notes  |  CreatedDate  |  Created By
    1   |  'VisitorAnalytics'  |  Visitors  |  SUM(Views)  |  >           |  null    |  10          |  n/a    |  1/1/2012     |  JohnDoe
    

    Then once these records are created, you will use them by injecting the tables into the from clause, columns into the where clause for your dynamic sql.

    I know this may sound confusing, but what you are asking is a fairly complex solution. But ultimately you just want to store the rules together in one place where you can loop through to dynamically build then execute a SQL to generate your report. Hopefully this points you in the right direction.

提交回复
热议问题