Error[8]: Undefined offset: 1015, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap { [+++] [+++][+++][+++]expression[+++]
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1016, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  [+++][+++][+++]expression[+++]
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1017, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  [+++][+++]expression[+++]
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1018, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  [+++]expression[+++]
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1019, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  expression[+++]
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 1020, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  expression
    [+++]

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
swift定义iOS数据库框架5——修改数据和删除数据(改)_app_内存溢出

swift定义iOS数据库框架5——修改数据和删除数据(改)

swift定义iOS数据库框架5——修改数据和删除数据(改),第1张

修改数据和删除数据 修改数据1、更新所有更新SQL即更新所有扩展 `QueryType`添加`update`方法扩展`Connection`添加`run`方法,执行SQL语句 2、条件更新(where)更新SQL,添加条件扩展 `QueryType`添加条件方法`filter` 3、内容替换(replace) 删除数据1、删除所有2、条件删除(where条件)

修改数据 1、更新所有


跟新 *** 作

	let update = users.update(email <- "dream@qq.com", phone <- "88888888")
    print(update.asSQL())
    try! db.run(update)
更新SQL即更新所有
public struct Update : ExpressionType {
    
    public var template: String
    public var bindings: [Binding?]
    
    public init(_ template: String, _ bindings: [Binding?]) {
        self.template = template
        self.bindings = bindings
    }
}
扩展 QueryType添加update方法
	public func update(_ values: Setter...) -> Update {
        return update(values)
    }
    
    public func update(_ values: [Setter]) -> Update {
        //SQL语句分段存储
        //第一个元素:Expression(literal: "UPDATE")->对应字符串->"update"
        //第二个元素:tableName()->对应表名称->"users"
        //第三个元素:Expression(literal: "SET")->对应->"set"
        //第四个元素:", ".join(values.map { " = ".join([$0.column, $0.value]) })->字段
        //例如:email = 'dream@qq.com', phone = '88888888'
        //第四个元素步骤->首先是拼接"="号,其次在拼接","号
        //形成完整SQL语句:update users set email = 'dream@qq.com', phone = '88888888'
        //注意:这么多的表达式,最终都会组装为一个表达式
        let clauses: [Expressible?] = [
            Expression<Void>(literal: "UPDATE"),
            tableName(),
            Expression<Void>(literal: "SET"),
            ", ".join(values.map { " = ".join([$0.column, $0.value]) }),
        ]
        //join拼接SQL语句相关
        //注意:每一个关键字之间需要" "空格隔开
        return Update(" ".join(clauses.compactMap { $0 }).expression)
    }
扩展Connection添加run方法,执行SQL语句
    @discardableResult public func run(_ query: Update) throws -> Int {
        //表达式
        //SQL->expression
        let expression = query.expression
        //队列->同步代码块
        return try sync {
            try self.run(expression.template, expression.bindings)
            //返回执行结果
            return self.changes
        }
    }
2、条件更新(where)

更新SQL,添加条件
	let filter = users.filter(name == "hello")
	try! db.run(filter.update(email <- "dream@qq.com"))
扩展 QueryType添加条件方法filter
    public func filter(_ predicate: Expression<Bool>) -> Self {
        return filter(Expression<Bool?>(predicate))
    }
    //SQL子句(排序->order by,分组->group...)
    public func filter(_ predicate: Expression<Bool?>) -> Self {
        var query = self
        //核心:也就是拼接条件
        //条件一:id = 1
        //条件二:name = "NSLog"
        //where id = 1 and name = "NSLog"
        query.clauses.filters = query.clauses.filters.map { && } predicate ?? return predicate
        } query
    QueryClauses
注意一:Value增加一个Bool类型
Bool过滤条件结构体,增加一个filters类型var
    : filtersExpression <Bool//增加一个Int64类型?>?

数据库里面,Bool类型用Int表示

extension
//注意:Int64->对应数据库类型->INTEGER
Int64 : Number ,Value //数据库类型 {
    public
    static let = declaredDatatype "INTEGER" public
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Int64 -> return {
        } datatypeValue
    public
    
    var : datatypeValueInt64 return {
        self }
    }
extension

//注意:数据库里面->Bool类型->0,1分别表示true、false,最终还是Int类型
Bool : Binding ,Value public {
    static var = declaredDatatype Int64 .publicdeclaredDatatype
    
    static func fromDatatypeValue (_: datatypeValueInt64 )Bool -> return {
        != datatypeValue 0 }
    public
    
    var : datatypeValueInt64 return {
        self ? 1 : 0 }
    }
&&
注意二:条件运算符:“public
区分系统->方法重载(运算符重载)->方法名称相同,但是参数列表不同(类型不同)
func && (:lhsExpression <Bool,>: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,>: rhsBool )Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsExpression <Bool,?>: rhsBool )Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)>Expression -> <Boolreturn> {
    "AND" .infix(,lhs) rhs}
public
func && (:lhsBool ,: rhsExpression <Bool)?>Expression -> <Boolreturn?> {
    "AND" .infix(,lhs) rhs}
==
注意三:条件运算符:“//例如:
//"="中缀->infix
//name属性
//NSError
//name = 'NSError'
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,>: rhsV )Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsExpression <V,?>: rhsV ?)Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = rhs else rhs return { "IS" .infix(,lhsExpression <V(?>:valuenil ))} return
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ,: rhsExpression <V)>Expression -> <Boolwhere> V .Datatype: Equatable return {
    "=" .infix(,lhs) rhs}
public
func ==< V: Value (>:lhsV ?,: rhsExpression <V)?>Expression -> <Boolwhere?> V .Datatype: Equatable guard {
    let = lhs else lhs return { "IS" .infix(Expression<V(?>:valuenil ),) rhs} return
    "=" .infix(,lhs) rhs}
replace

多支持几个类型,系统本身就是基本数据类型,让它支持对象类型,相当于给系统扩展功能

3、内容替换(replace)

在数据库里面也有替换SQL语法:= ,并且只有String字段才可以replace

    let filter . usersfilter(==id "1" )!
    try. dbrun(.filterupdate(<name -. namereplace("r",: with"i" )))QueryType
注意一:替换的谁?
替换的是表达式:字段,所以说功能在字段身上注意二:替换位置限定:从头开始查找替换
从左边往右边依次查找,本质上和编程开发一样的顺序 删除数据 1、删除所有

- 扩展delete()增加删除所有数据方法public

	func delete ()Delete -> let {
        : clauses[ Expressible?]= [ Expression
            <Void(>:literal"DELETE FROM" ),tableName
            (),]
        return
        Delete (" ".join(.clauses}compactMap { ) .)}expressionWHERE
    whereClause
2、条件删除(where条件)

增加fileprivate条件表达式var
	: Expressible whereClause? guardlet {
        = . filters else clausesreturnfilters nil {
            } return
        " "
        
        . join([Expression<
            Void(:>"WHERE"literal) ,])
            filters
        }whereClause
    update()

delete()放入publicfunc

	update ( _:[ valuesSetter ])Updatelet -> : {
    [ clausesExpressible ?]=[ Expression <
        Void(:>"UPDATE"literal) ,tableName(
        ),Expression<
        Void(:>"SET"literal) ,", ".
        join(." = "values.map { join([.,.]column) })value,] //join拼接SQL语句相关//注意:每一个关键字之间需要" "空格隔开return
        whereClause
    Update
    (
    " "
    . join(.}).clauses)compactMap { } publicfuncdeleteexpression(
)
	Delete let :[Expressible -> ? {
        ] clauses= [Expression<Void ( :
            "DELETE FROM"),>tableNameliteral( ),]
            returnDelete(" "
            whereClause
        .
        join (.}).)clauses}compactMap {  expression
    

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/993193.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存