Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Insert

插入数据

export
class

Insert

Hierarchy

  • Insert

Index

Methods

Methods

Static insert

  • insert(conn: ConnectionPool, pars: object, tran?: MssqlTransaction): Promise<any>
  • 插入一条数据
    注意:插入字段会根据table表中实际字段进行匹配,只有实际存在的字段才会插入。见下面例子。
    注意:如需事务处理,请传入tran参数。
    
    static
    memberof

    Insert

    example
    tbl1表结构:
    create table tbl1 (
     f1 int,
     f2 int,
     f3 int
    )
    例1,以下相当于SQL: insert into tbl1(f1, f2, f3) values(1, 2, 3);
    let result = await Insert.insert(conn, {
      data: { f1: 1, f2: 2, f3: 3, f4: 4 }, // f4 不是字段,插入成功
      table: 'tbl1'
    });
    例2,以下相当于SQL: insert into tbl1(f1, f2) values(1, 2);
    let result = await Insert.insert(conn, {
      data: { f1: 1, f2: 2 }, // 少一个字段f3,插入成功
      table: 'tbl1'
    });
    

    Parameters

    • conn: ConnectionPool

      数据库连接对象

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

    Returns Promise<any>

    Promise对象