In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to make the front-end programmer complete the project without the back-end". The content in the article is simple and clear, and it is easy to learn and understand. let's study and learn "how to let the front-end programmer finish the project without the back-end"!
What is the problem if Mysql is directly exposed to the public network for front-end use:
Ipaw O boundary = > performance considerations
Obtain multiple pieces of data in batch
Aggregate the data by count / sum etc.
Calculate the aggregation result in advance, redundant fields
Organizational boundaries = > Security considerations
The resulting order price should be equal to the sum of the unit price of the commodity.
To create an out-of-warehouse order, you need a xxx leader signature sheet.
Data permission check to prevent illegal access
Verify business rules
To achieve Backend as a "Database" is to answer how to solve the above questions.
User table
The permissions of Mysql / Postgresql are too thick. It must be a layer outside Mysql / Postgresql to verify permissions. Here are the following challenges to solve
B-side permissions need to be very detailed, not only to the line, but even to the grid. Permissions may be granted by position, or they may be granted temporarily because of work order assignments.
The overhead of permission verification should not be too high. If it is used for C-end business, the number of documents and users may be very large. Reduce the overhead introduced by row-level permissions. So you need to be able to open different authorization modes as needed.
Users who are not logged in need to log in or can browse anonymously. How to make it easy to give appropriate rights to access without users.
Access by non-real human users, such as nocturnal batch processing, requires an account that can have robots.
How is the initialization of the account described? who will assign the original administrator?
If you have multiple Project, each Project has its own user architecture and different User tables. What User identity do the two Project use to access each other?
After solving the above problems, we have obtained a "Database" with built-in permissions, which can be opened to the public network for front-end access. When actually pulling the data, the identity of the human user is used. As long as the user has permission to access the data table or row to be accessed, it can be accessed, otherwise it cannot be accessed.
Business data sheet
Write a Typescript class, and then build the Mysql table. Just like Java Hibernate.
@ Biz.profile ('buyer', 'read') @ Biz.profile (' Manager', 'read',' create', 'update',' delete') @ Biz.profile ('Manager', 'read',' create', 'update',' delete') @ Biz.authentic ({rowPolicy: 'public'}) @ Biz.published export class RegionFreightTmpl extends Biz.ActiveRecord {@ Biz.lookup public readonly freightTmpl: FreightTmpl / / Billing method: by piece (currently only by piece) public freightTmplType: string; public firstPrice: number; public firstAmount: number = 1; public additionalPrice: number; public additionalAmount: number = 1; public regions?: string;}
When querying, you can directly use this class to refer to this database table.
View chart
The prerequisite for doing a good job of permission verification is a simple query that only exposes a single table. What about count / sum / join? Are you going to invent a variant of SQL and then do SQL parsing?
A simple approach is to introduce the concept of "view chart". These aggregate queries are modeled as a virtual view chart. In this way, it is still a single table query when querying.
The problem of how to express complex query in rpc request is solved, and sql over http is avoided.
It solves the problem that it is difficult to determine what the target is by permission verification.
Materialized visual chart
It will be very slow if all aggregate queries are calculated on demand. Often we need some intermediate results that are aggregated by date and dimension in advance. This can be expressed in a materialized visual chart.
@ (Biz.view`Select id, gender, age, city, SUM (OrderItem.cost) AS total FROM ${impactSet} JOIN ${User} on User.id = impactSet.userId LEFT JOIN ${Order} on User.id = Order.userId LEFT JOIN ${OrderItem} on Order.id = OrderItem.orderId`) @ (impac tSet`SELECT DISTINCT (Order.userId) AS userId FROM ${Order} `) @ (impactSet`SELECT DISTINCT (Order.userId) AS userId FROM ${OrderItem} JOIN ${Order} on Order.id = OrderItem.orderId`) @ Biz.source (Starriness {dataSource: 'clickhouse'}) export class UserWithTotal extends Biz.SqlView {public readonly id: string Public readonly userId: string; public readonly created_at: Date; public readonly total: number;}
The problem with materialized views is when to refresh. By defining impactSet with SQL, we can trigger the refresh of the materialized view chart materialized in clickhouse by mysql binlog.
User behavior table
The source of the materialized view is business data. User behavior is not suitable for direct insertion into mysql because of the large amount of data. Provide a separate wide table of user behavior to record what the user has done. Writes can be buffered in memory or through queues such as kafka.
The columns of the wide table should be expanded according to business requirements, and these fields should be added if the business is concerned about the order id or product id that the user operates. The approximate api is also similar to the reporting interface of established analyst vendors such as mixpanel.
The materialized view can join the user behavior table and the business data table to get the analysis results when calculating the report.
Batch query
Rpc roundtrip can only send one query at a time. It's too slow. It would be nice to support one array and submit multiple queries at a time. As for how the front-end code aggregates queries from multiple components into a rpc, it depends on how the front-end data query framework works. Nothing more than a global buffer, in the "appropriate time" to brush this buffer, batch check.
Stored procedure
Fine-grained user rights can only solve the problem that the data is completely owned by one user. Most of the time, the data is collaborative data and there are multiple stakeholder, so the data must be modified by negotiated rules, not by a user. For example, you can decide what to write in your diary today, but you can't decide to change your order for dinner tonight to 0. The diary is owned by you, but the order is concerned by many interested parties.
To solve the problem of writing after business rule verification is the stored procedure. The front-end students must want to use javascript to write stored procedures. In fact, it is the so-called cloud function of FaaS. In essence, there is still back-end code, just a different group of people to write it.
If the business rules are simple, such as just a transformation diagram of a state machine, you can replace code with configuration. Of course, most of the time, the complex business logic, javascript is the most intuitive.
Data Migration
Database table structure has changed, it is certain to write SQL to upgrade the database, the standard practice is nothing to say.
Backend as a Database
Provides something similar to Database using the RPC interface
The back-end business is divided into preset concepts such as User table / business data table / view chart / materialized view chart / user behavior table / stored procedure / DataMigration.
With the exception of "writing to be verified by business rules", other back-end interfaces do not need a general programming language and can be solved by configuration or SQL definition
This solution is neither GraphQL nor classical BFF.
Thank you for your reading, the above is the content of "how to make the front-end programmer can complete the project without the back end". After the study of this article, I believe you have a deeper understanding of how to make the front-end programmer complete the project without the back end, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.