Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 如何从数据库中只获取更新的行并使应用程序更高效_Sql_Database_Laravel_Vue.js - Fatal编程技术网

Sql 如何从数据库中只获取更新的行并使应用程序更高效

Sql 如何从数据库中只获取更新的行并使应用程序更高效,sql,database,laravel,vue.js,Sql,Database,Laravel,Vue.js,我正在创建laravel/vue.js CRUD应用程序,目前一切正常,但我担心更新数据后对数据库的查询质量 每次更新数据库中的行时,我都使用getAllData()。现在,当我在数据库中有一些记录时,每次询问服务器并在vue中呈现新列表并不是一个问题,但当我有几千行记录时,我的应用程序会变得缓慢而沉重 现在我更新数据库如下: 这是我的vue.js更新功能的一部分: 这是我的vue.js getAllData函数: 我的工资管理员: 我的更新功能: 是否有任何方法可以更有效地进行更新,例如从数据

我正在创建laravel/vue.js CRUD应用程序,目前一切正常,但我担心更新数据后对数据库的查询质量

每次更新数据库中的行时,我都使用getAllData()。现在,当我在数据库中有一些记录时,每次询问服务器并在vue中呈现新列表并不是一个问题,但当我有几千行记录时,我的应用程序会变得缓慢而沉重

现在我更新数据库如下:

这是我的vue.js更新功能的一部分:

这是我的vue.js getAllData函数:

我的工资管理员:

我的更新功能:


是否有任何方法可以更有效地进行更新,例如从数据库中只获取更新的行,并将其放入我现有的带有行的对象中?或者我不应该担心它?

没有看到你的逻辑:

控制器可以返回记录:

return response(['payment' => $payment], Response::HTTP_OK);
axios方法可以观察到该响应,然后对索引进行替换(就像之前获取索引时所做的那样)


只要
数据
中实例化为
[]
,那么它是可观察的。

如果您需要针对特定时间段更新行。

另外,你可以做一件事。当用户更新行时,u可以将唯一ID存储在新表中,您可以通过该ID获取数据。然后,当您不需要最新更新的数据时,您可以从新表中删除该ID

通过ID更新行时

  • 在新表中插入id
  • 更新记录
  • 如果只需要更新记录>>请根据 需求>>从新表获取id并与主表连接
  • 当您不需要最新更新的记录时。从中删除记录 新表格。>>按照要求使用后端条件>> 从主表获取

  • 正如@Ohgodwhy所说,我像这样修改了代码,现在它运行良好

    更新功能

    public function update(Request $request, $id)
    {
        $payments = new Payments();
        payments::where('id', $id)->update($request->all());
        return response(payments::where('id', $id)->get(), Response::HTTP_OK);
    }
    
    axios

        updateStatus: function(id){
    
               var index = _.findIndex(this.rows,["id",id]);
    
                if (this.rows[index].pay_status=="oczekuje"){
                    axios.put("http://127.0.0.1:8000/api/payments/"+id,{pay_status:"zapłacono"}).then((response)=>{
                    this.rows[index].pay_status=response.data[0].pay_status;
                    this.waitingInvoices = this.countInvoices();
                    this.toPay = this.calculatePayment();
    
    
                }); 
                } else if (this.rows[index].pay_status=="zapłacono"){
                   axios.put("http://127.0.0.1:8000/api/payments/"+id,{pay_status:"oczekuje"}).then((response)=>{
                   this.rows[index].pay_status=response.data[0].pay_status;
                   this.waitingInvoices = this.countInvoices();
                   this.toPay = this.calculatePayment();
    
                }); 
                }
        },
    

    向我们展示来自控制器的
    api/payments/{id}
    路由的逻辑,而不是您@Ohgodwhy。我忘记了api/payments/{id}的逻辑,但现在我更新了我的帖子。你能帮我把问题问清楚吗?谢谢。你有这样一个解决方案的例子吗?对不起,我不能提供代码。但是你可以跟随潮流。来自ans(刚刚编辑)
    public function update(Request $request, $id)
    {
        $payments = new Payments();
        payments::where('id', $id)->update($request->all());
    }
    
    return response(['payment' => $payment], Response::HTTP_OK);
    
    .then((response) => {
        const { payment } = response.data;
    
        this.items[index] = payment;
    })
    
    public function update(Request $request, $id)
    {
        $payments = new Payments();
        payments::where('id', $id)->update($request->all());
        return response(payments::where('id', $id)->get(), Response::HTTP_OK);
    }
    
        updateStatus: function(id){
    
               var index = _.findIndex(this.rows,["id",id]);
    
                if (this.rows[index].pay_status=="oczekuje"){
                    axios.put("http://127.0.0.1:8000/api/payments/"+id,{pay_status:"zapłacono"}).then((response)=>{
                    this.rows[index].pay_status=response.data[0].pay_status;
                    this.waitingInvoices = this.countInvoices();
                    this.toPay = this.calculatePayment();
    
    
                }); 
                } else if (this.rows[index].pay_status=="zapłacono"){
                   axios.put("http://127.0.0.1:8000/api/payments/"+id,{pay_status:"oczekuje"}).then((response)=>{
                   this.rows[index].pay_status=response.data[0].pay_status;
                   this.waitingInvoices = this.countInvoices();
                   this.toPay = this.calculatePayment();
    
                }); 
                }
        },