Place to write laravel RAW queries? - laravel

We are currently working with a big laravel 5.2 project. For our query, we always try to use Eloquent ORM. But sometimes we need to use RAW queries.
We think in future, we have to write more RAW queries. So we need a separate place and a well-organised way to write RAW queries.We don’t want to write raw query in our controller and model.
Is there any other place where we can put raw queries. Or what is the best procedure to write raw queries(Write a separate file or repository etc.)

You could use scopes
For each group of related queries, I would create a file in scopes directory structured according to your models structure.
This will give you a central place where you could add or edit your raw queries.

Related

How to fetch the data from database using spring boot without mapping

I have a database and in that database there are many tables of data. I want to fetch the data from any one of those tables by entering a query from the front-end application. I'm not doing any manipulation to the data, doing just retrieving the data from database.
Also, mapping the data requires writing so many entity or POJO classes, so I don't want to map the data to any object. How can I achieve this?
In this case, assuming the mapping of tables if not relevant, you don't need to use JPA/Hibernate at all.
You can use an old, battle tested jdbc template that can execute a query of your choice (that you'll pass from client), will serialize the response to JSONObject and return it as a response in your controller.
The client side will be responsible to rendering the result.
You might also query the database metadata to obtain the information about column names, types, etc. so that the client side will also get this information and will be able to show the results in a more convenient / "advanced" way.
Beware of security implications, though. Basically it means that the client will be able to delete all the records from the database by a simple query and you won't be able to avoid it :)

Is there an Oracle API to implement readonly views over a structured sequence of bytes

Suppose I want to use an Oracle database, and I have some flat binary file containing structured data. Suppose I have a relational model that fits this data structure.
Does Oracle provide an API to implement some adapter to be able to relationally query this sequence of bytes as a set of views?
If so:
where should the data reside?
what version offers this feature?
If no:
is there any other RDBMS that offers such an API?
You can use an external table. Normally, external tables must use text columns, but you can use the PREPROCESSOR directive to specify a script that will transform the source file before loading it.
You could also use UTL_FILE to load the table from disk and do whatever you want to it in the database. This could include a pipelined table function that you access with the TABLE operator.

Query to read data from URL

I am using Greenplum Database.
Need to write query or may be function to read data from a URL.
Say a sharepoint URL is there, which contains some tabular data.
I need to write a query to fetch that Data from within the sql query or function.
I can get http_get, but its not helpful because the version is 8.2x.
I also tried python as pg language, it is also not working as it is listed as untrusted language. Hence looking for some alternative.
Have you tried using web external tables:
https://gpdb.docs.pivotal.io/5170/admin_guide/external/g-creating-and-using-web-external-tables.html

Performance and Security with Laravel Query Builder vs Stored Procedures

Im new to Laravel and have been reading up on its query builder, however haven't been able to find a definite answer. I know that stored procedures are essentially like functions that are stored inside the database to increase performance and security, but does Laravel's query builder work as a replacement for that?
Essentially, would it be necessary to use both stored procedures AND the Laravel query builder, or would using the query builder be enough since the functions are already built into Laravel?
Query builder is not a replacement of stored procedures. It works using PHP PDO. Stored procedures are a set of SQL queries in the compiled form. It helps to reduce network traffic and improve performance.

What is the easiest way to save a LINQ query for later use?

I have a request for a feature to be able to save a user's search for later.
Right now I'm building LINQ statements on the fly based on what the user has specified.
So I started wondering, is there an easy way for me to simply take the query that the user built, and persist it somewhere, preferably my database, so that I can retrieve it later?
Is there some way of persisting the query as XML or perhaps JSON, and then reconstituting the query later?
Never done this before, but I've had this idea:
Rather than having the query run against your database directly, if you were to have it run against an OData endpoint, you could conceivably extract the URL that is generated as the query string, and save that URL for later use. Since OData has a well-though-out spec already, you would be able to profit from other people's labor.
I'd go with a domain-specific object here even if such goodies did exist -- what happens when you save serialized queries in LINQ and your underlying model changes, invalidating everyone's saved queries. Using your own data format should shield you from this to some extent.
Take a look at the Expression class. This will allow you to pre-compile a query. Although persisting this for later use to the DB for better performance is questionable.
I'm writing this as I watch this presentation at PDC10. Just after the 1-hour mark, he shows how he's built a JSON serializer for expression trees. You might find that interesting.

Resources