Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Replace

替换

export
class

Replace

Hierarchy

  • Replace

Index

Methods

Methods

Static replace

  • replace(conn: ConnectionPool, pars: object, tran?: MssqlTransaction): Promise<any>
  • 根据主键替换数据
    注意:如需事务处理,请传入tran参数。
    
    static
    memberof

    Replace

    example
    tbl1表结构:
    create table tbl1 (
     f1 int primary key,
     f2 int,
     f3 int
    )
    例1:相当于 replace into tbl1(f1, f2, f3) values(1,2,3)
    当存在 f1 = 1的数据时,相当于update tbl1 set f2=2,f3=3 where f1=1
    当不存在f1= 1的数据时,相当于insert into tbl1(f1,f2,f3) values(1,2,3)
    let result = await Replace.replace(conn, {
      data: { f1: 1, f2: 2, f3: 3 },
      table: 'tbl1'
    });
    

    Parameters

    • conn: ConnectionPool

      数据库连接对象

    • pars: object
      • Optional chema?: string
      • data: __type
      • Optional database?: string
      • table: string
    • Optional tran: MssqlTransaction

    Returns Promise<any>

    Promise对象