Advertisement
Guest User

Untitled

a guest
Apr 17th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public addPrueba(element :any)
  2.   {
  3.     var sql = "INSERT INTO perro (edad, nombre) VALUES (:a, :b)"
  4.     var binds = [
  5.       { a: 1, b: "Taco" },
  6.       { a: 23, b: "PUTABIDA" },
  7.     ];
  8.  
  9.     var options = {
  10.       autoCommit: true,
  11.       bindDefs: {
  12.         a: { type: oracledb.NUMBER },
  13.         b: { type: oracledb.STRING, maxSize: 64 }
  14.       }
  15.     };
  16.  
  17.     oracledb.getConnection({
  18.       user: "system",
  19.       password: "51264",
  20.       connectString: "localhost:1521/xe"
  21.     }).then(async (connection: oracledb.IConnection) => {
  22.       console.log("Connection finally created in constructor")
  23.       await connection.execute(sql, binds, options).
  24.         then((result)=>{console.log("Rows: \n", result.rowsAffected)})
  25.         .catch((err)=>{console.error("Promise rejected - ",err)});
  26.       connection.close().then( () => { console.log("Conection closed.") } )
  27.       .catch((err) => { console.error(err.message) });
  28.     }).catch((err: any) => {
  29.       console.error(err.message);
  30.     });
  31.   }
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement