Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Replace

替换

export
class

Replace

Hierarchy

  • Replace

Index

Methods

Methods

Static replace

  • replace(conn: Connection, pars: object): Promise<Object>
  • 根据主键替换数据
    注意:此方法没有开启事务。如需开启事务,见 Transaction
    
    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: Connection

      数据库连接对象

    • pars: object
      • data: __type
      • Optional database?: string
      • table: string

    Returns Promise<Object>

    Promise对象