FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
nodejs-driver/samples/ExportCSVResult.ts at develop · Teradata/nodejs-driver · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
Teradata
/
nodejs-driver
Public
Notifications
You must be signed in to change notification settings
Fork
13
Star
15
Code
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
nodejs-driver
/
samples
/
ExportCSVResult.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
47 lines (40 loc) · 1.48 KB
Breadcrumbs
nodejs-driver
/
samples
/
ExportCSVResult.ts
Copy path
File metadata and controls
47 lines (40 loc) · 1.48 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
38
39
40
41
42
43
44
45
46
47
// Copyright 2023 by Teradata Corporation. All rights reserved.
// This sample program demonstrates how to export the results from a select statement into a csv file.
// 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 voltab (c1 integer, c2 varchar(100)) on commit preserve rows"
)
;
console
.
log
(
"Inserting data"
)
;
cur
.
execute
(
"insert into voltab values (?, ?)"
,
[
[
1
,
""
]
,
[
2
,
"abc"
]
,
[
3
,
"def"
]
,
[
4
,
"mno"
]
,
[
5
,
""
]
,
[
6
,
"pqr"
]
,
[
7
,
"uvw"
]
,
[
8
,
"xyz"
]
,
[
9
,
""
]
,
]
)
;
const
sFileName
:
string
=
"dataJs.csv"
;
console
.
log
(
"Exporting table data to file"
,
sFileName
)
;
cur
.
execute
(
"{fn teradata_write_csv("
+
sFileName
+
")}select * from voltab order by 1"
)
;
try
{
console
.
log
(
"Reading file"
,
sFileName
)
;
const
sRows
:
string
[
]
[
]
=
parse
(
fs
.
readFileSync
(
sFileName
,
{
encoding
:
"utf-8"
}
)
)
;
console
.
log
(
sRows
)
;
}
finally
{
fs
.
unlinkSync
(
sFileName
)
;
}
}
finally
{
cur
.
close
(
)
;
}
}
finally
{
con
.
close
(
)
;
}
Back
|
FazBrowse Home
|
New Git URL