当前位置:网站首页>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
边栏推荐
- 【Torch】最简洁logging使用指南
- 【BERT,GPT+KG调研】Pretrain model融合knowledge的论文集锦
- Conda 创建,复制,分享虚拟环境
- Oracle RMAN semi automatic recovery script restore phase
- Sqli labs customs clearance summary-page4
- MySQL composite index with or without ID
- TCP attack
- 【信息检索导论】第三章 容错式检索
- php中树形结构转数组(拉平树结构,保留上下级排序)
- Oracle rman自动恢复脚本(生产数据向测试迁移)
猜你喜欢
随机推荐
ORACLE 11.2.0.3 不停机处理SYSAUX表空间一直增长问题
The first quickapp demo
Illustration of etcd access in kubernetes
【Torch】最简洁logging使用指南
2021-07-05c /cad secondary development create arc (4)
CSRF attack
JSP智能小区物业管理系统
Proteus -- RS-232 dual computer communication
Oracle EBS interface development - quick generation of JSON format data
SSM实验室设备管理
Take you to master the formatter of visual studio code
叮咚,Redis OM对象映射框架来了
php中树形结构转数组(拉平树结构,保留上下级排序)
Practice and thinking of offline data warehouse and Bi development
Write a thread pool by hand, and take you to learn the implementation principle of ThreadPoolExecutor thread pool
離線數倉和bi開發的實踐和思考
SSM学生成绩信息管理系统
DNS attack details
Oracle 11g uses ords+pljson to implement JSON_ Table effect
软件开发模式之敏捷开发(scrum)








