Why there is no Active Record REST adapter

We have been working on various projects using ActiveResource for a couple of years. ActiveResource seems to work great if you use Rails on the client and server side.

Problems with ActiveResource

We use Scala on the server side and constantly encounter "Oh, ActiveResource does not want the API to be <do this standard thing> " or "ActiveResource did <this weird thing> ", so we need to change the server to support client requirements. This has all been discussed before, I know.

Another problem is that many stones and libraries require ActiveRecord. I can’t calculate the number of gems we used to “require” your model to use ActiveRecord, even if they don’t actually use the actual AR functionality. This seems to be mainly because it is a simple way to develop gems. "I use ActiveRecord and I can’t imagine that someone wouldn’t use it, so I just demand that I figure out a more general way instead" (note, I did it myself, so I’m not just complaining)

So, if we use ActiveResource, we need to break the server for it to work, and we cannot use most of what makes Rails great.

REST adapter?

All this made us ask the question "Why does ActiveResource exist at all?" I mean, why do you have this secondary data storage path? Why is ActiveResource not a REST adapter? With the REST adapter, you can have all the good things in all the gems and don't have to fight the ActiveResource effect. You just build your model in the same way as any model.

So, I began to explore the building. This is actually not at all difficult. A few hours of work, and you can create basic functionality. Otherwise, REST and SOAP examples are used, so this is possible.

So the question is coming back. If it's that simple, why the hell hasn't it been done before?

Not just a data warehouse

I came up with what interests me, this is the answer. Raising the scaffold for this, I quickly ran into a problem. REST does two things very well: 1) act on this object and 2) act on all objects. In fact, this is pretty much the limit of the REST standard.

And so I started to wonder if scope is a REST adapter. The ActiveRecord subsystem seems to need more than just "get one" and "get everything." It was based on a request to the data warehouse as you like.

Factual question

So, the actual question is: is there an Active Record REST adapter simply because REST does not define a standardized way of saying "give me all the cars where the car is in the same parking lot, since these drivers and drivers have a key."

+4
source share
2 answers

It is right.

Unlike databases that have SQL as the standard way to express conditions, REST does not have a standard to support all ActiveRecord functions, such as joins, groups, and having.

How many hours of work do you think will be required to complete correlated queries or subqueries?


I am not here by chance. This concept touches on some of the personal projects that I reviewed, with some of the same issues that I was thinking about.

ActiveRecord supports all of SQL, which is much more efficient than most people use or need. Basically, each part of the SQL statement has an ActiveRecord method that takes a row to populate this SQL section.

You want to restrict the client to a part of ActiveRecord. You will still need NULL, NOT NOT. You need comparisons such as less and more. You want to support OR statements for "field1 IS NULL OR field1 = ''".

To make all the comparison materials, for example, where (["updated_at>?", Cutoff]), you will need a RESTful server, more reliable than existing web services. The server will need to use your gem or be created with recommendations for the implementation of all functions.

So in the end why? You embed a limited database API by navigating through a network with string URLs instead of binary packages, into the database engine that you implement.

0
source

On the other hand, if there is a standard for this, then such an implementation may be good.

If there was an implementation that could be installed on a RESTful web server, which, although not as powerful as SQL, could make indexed queries, process index indexes of simple non-indexable expressions to qualify the return of records and sort, (even if the transfer this in the SQL database does all the work), you could include it on the server, and products like Crystal Reports could be designed to use the standard for the report client.

Passing the web server API level can provide a way to limit the restrictions on what database operations can be performed to provide more security than fully accessing the database. In addition, logic can be added to the web service for auditing and processing events arising from CRUD operations (essentially triggers). Yes, database products provide security policies, triggers, and stored procedures for performing these tasks, but with the product we are discussing, you can make it easier in ruby ​​than using database functions.

You can also have pseudo data that is computed from ruby ​​code but acts like database records, along with sharing a RESTful database. Of course, databases can do this, which stores procedures, and some support writing stored procedures in Java, but that would be better because it would be easier to implement and could be written in ruby.

0
source

Source: https://habr.com/ru/post/1394781/


All Articles