Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Update

更新数据

export
class

Update

Hierarchy

  • Update

Index

Methods

Static update

  • update(conn: ConnectionPool, pars: object, tran?: MssqlTransaction): Promise<boolean>
  • 根据主键更新一条数据,主键不能更新。如需更新主键,见Update.updateByWhere
    注意:如需事务处理,请传入tran参数。
    
    static
    memberof

    Update

    example
    tbl1表结构:
    create table tbl1 (
     f1 int,
     f2 int,
     f3 int,
     f4 int,
     primary key(f1, f2)
    )
    例1:相当于SQL update tbl1 set f3=3, f4=4 where f1=1 and f2=2
    let result = await Update.update(conn, {
       data: { f1: 1, f2: 2, f3: 3, f4: 4 },
       table: 'tbl1'
    });
    例2:相当于SQL update tbl1 set f3=3 where f1=1 and f2=2
    let result = await Update.update(conn, {
       data: { f1: 1, f2: 2, f3: 3 },
       table: 'tbl1'
    });
    例3:相当于SQL update tbl1 set f3=3, f4=4
    let result = await Update.update(conn, {
       data: { f3: 3, f4: 4 },
       table: 'tbl1'
    });
    

    Parameters

    • conn: ConnectionPool

      数据库连接对象

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

    Returns Promise<boolean>

    Promise对象

Static updateByWhere

  • updateByWhere(conn: ConnectionPool, pars: object, tran?: MssqlTransaction): Promise<boolean>
  • 根据where更新一条数据,可以更新主键
    注意:如需事务处理,请传入tran参数。
    
    static
    memberof

    Update

    Parameters

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

    Returns Promise<boolean>

    Promise对象