GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — nodejs-driver/samples/LoadCSVFile.ts at develop · Teradata/nodejs-driver

Expand file tree

/

LoadCSVFile.ts

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
37 lines (30 loc) · 1.61 KB
/

LoadCSVFile.ts

Copy path

File metadata and controls

37 lines (30 loc) · 1.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Copyright 2023 by Teradata Corporation. All rights reserved.
// This sample program demonstrates two different approaches to load data values
// from a CSV file and insert those data values into a database table.
// This sample program requires the airports.csv file to be located in the current directory.
// Run "npm install csv" to install the CSV module
import * as fs from "fs";
import { parse } from "csv-parse/sync";
// @ts-ignore
import * as teradatasql from "teradatasql";
const con: teradatasql.TeradataConnection = teradatasql.connect({ host: "whomooz", user: "guest", password: "please" });
try {
const cur: teradatasql.TeradataCursor = con.cursor();
try {
cur.execute("create volatile table Airports (City varchar(100), Airport varchar(100), AirportCode varchar(10)) on commit preserve rows");
console.log("Slower approach - use the csv module to parse data values from a CSV file");
const records: string[][] = parse(fs.readFileSync("airports.csv", { encoding: "utf-8" }));
cur.execute("insert into Airports (?, ?, ?)", records);
cur.execute("select AirportCode, Airport, City from Airports order by AirportCode");
console.log(cur.fetchall());
cur.execute("delete from Airports");
console.log("Faster approach - the driver loads data values from a CSV file");
cur.execute("{fn teradata_read_csv(airports.csv)}insert into Airports (?, ?, ?)");
cur.execute("select AirportCode, Airport, City from Airports order by AirportCode");
console.log(cur.fetchall());
} finally {
cur.close();
}
} finally {
con.close();
}
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.