当前位置:网站首页>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
边栏推荐
- MySQL composite index with or without ID
- @Transational踩坑
- Oracle EBS ADI development steps
- 华为机试题-20190417
- Oracle 11g sysaux table space full processing and the difference between move and shrink
- The first quickapp demo
- Oracle rman半自动恢复脚本-restore阶段
- Sqli labs customs clearance summary-page4
- MapReduce与YARN原理解析
- oracle EBS标准表的后缀解释说明
猜你喜欢
MySQL中的正则表达式
Practice and thinking of offline data warehouse and Bi development
架构设计三原则
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
搭建frp进行内网穿透
离线数仓和bi开发的实践和思考
如何高效开发一款微信小程序
Yaml file of ingress controller 0.47.0
MySQL无order by的排序规则因素
MapReduce concepts and cases (Shang Silicon Valley Learning Notes)
随机推荐
实现接口 Interface Iterable<T>
php中树形结构转数组(拉平树结构,保留上下级排序)
MySQL has no collation factor of order by
Check log4j problems using stain analysis
@Transitional step pit
php中通过集合collect的方法来实现把某个值插入到数组中指定的位置
使用Matlab实现:Jacobi、Gauss-Seidel迭代
Two table Association of pyspark in idea2020 (field names are the same)
JSP智能小区物业管理系统
【信息检索导论】第一章 布尔检索
2021-07-17c /cad secondary development creation circle (5)
ssm人事管理系统
ORACLE EBS ADI 开发步骤
中年人的认知科普
优化方法:常用数学符号的含义
Principle analysis of spark
Ceaspectuss shipping company shipping artificial intelligence products, anytime, anywhere container inspection and reporting to achieve cloud yard, shipping company intelligent digital container contr
读《敏捷整洁之道:回归本源》后感
使用Matlab实现:幂法、反幂法(原点位移)
【MEDICAL】Attend to Medical Ontologies: Content Selection for Clinical Abstractive Summarization