当前位置:网站首页>Find in laravel8_ in_ Usage of set and upsert
Find in laravel8_ in_ Usage of set and upsert
2022-07-02 07:19:00 【Snow wind in the night sky】
Preface
stay laravel8 Sometimes you need to use FIND_IN_SET Native MySql sentence , Accurately query whether a special string exists in the specified string like Unable to accurately match the problem .
for example :type Field ,type = 1,11,111.type = 2,22,222. use like Precise matching cannot be achieved during fuzzy query , It needs to be used FIND_IN_SET Exactly match the query .
usage
//DB::table(' Table name ')->whereRaw('FIND_IN_SET(?, Field name )',[ The string to query ])->get();
$type = 1;
// Code demonstration
$data1 = DB::table('file')->whereRaw('FIND_IN_SET(?,type)',[$type])->get();
$data2 = FileModel::whereRaw('FIND_IN_SET(?,type)',[$type])->get();
Preface
When solving the problem of inserting a large amount of data into the database table at one time upsert Method . Put... Here Laravel8 Instructions in official documents .
If you want to execute multiple in a single query upsert, So you should use upsert Method . The first parameter of the method consists of the value to be inserted or updated , The second parameter lists the columns that uniquely identify records in the corresponding table , The third and last parameter of this method is a column array , That is, if there are already matching records in the database , Columns that should be updated . If timestamp is enabled on the model ,upsert Method will be set automatically created_at and updated_at Time stamp .
App\Models\Flight::upsert([
['departure' => 'Oakland', 'destination' => 'San Diego', 'price' => 99],
['departure' => 'Chicago', 'destination' => 'New York', 'price' => 150]
], ['departure', 'destination'], ['price']);
usage
The actual use :
$insert_data = [
['name' => ' file 1', 'use' => ' quality ', 'type' => 1],
['name' => ' file 2', 'use' => ' Security ', 'type' => 2],
['name' => ' file 3', 'use' => ' speed of progress ', 'type' => 3],
];
FileModel::upsert($insert_data, ['name', 'use', 'type']);// Write the field value of the data table here
边栏推荐
- Data warehouse model fact table model design
- php中在二维数组中根据值返回对应的键值
- 使用 Compose 实现可见 ScrollBar
- Yolov5 practice: teach object detection by hand
- Use of interrupt()
- Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
- Spark SQL task performance optimization (basic)
- 【Ranking】Pre-trained Language Model based Ranking in Baidu Search
- Thinkphp5中一个字段对应多个模糊查询
- How to call WebService in PHP development environment?
猜你喜欢
随机推荐
MySQL无order by的排序规则因素
Analysis of MapReduce and yarn principles
Pyspark build temporary report error
外币记账及重估总账余额表变化(下)
TCP attack
Three principles of architecture design
Yaml file of ingress controller 0.47.0
view的绘制机制(二)
sqli-labs通關匯總-page2
【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
Oracle segment advisor, how to deal with row link row migration, reduce high water level
MySQL中的正则表达式
ORACLE EBS接口开发-json格式数据快捷生成
Proteus -- RS-232 dual computer communication
2021-07-19c CAD secondary development creates multiple line segments
Network security -- intrusion detection of emergency response
矩阵的Jordan分解实例
MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
Basic knowledge of software testing
spark sql任务性能优化(基础)









