Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

bximport.js 794 B

You have to be logged in to leave a comment. Sign In
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
  1. const fs = require('fs');
  2. const csv = require('csv-parser');
  3. const through = require('through2');
  4. const ioUtils = require('./io');
  5. const QueryEvalStream = require('./query-eval-stream');
  6. function importBXRatings(fn) {
  7. return ioUtils.openFile(fn)
  8. .pipe(ioUtils.decodeBadUnicode())
  9. .pipe(csv({
  10. separator: ';',
  11. escape: '\\'
  12. }))
  13. .pipe(through.obj((row, enc, cb) => {
  14. cb(null, {
  15. text: 'INSERT INTO bx_raw_ratings (user_id, isbn, rating) VALUES ($1, $2, $3)',
  16. name: 'insert-rating',
  17. values: [row['User-ID'], row['ISBN'].replace(/"/, ''), row['Book-Rating']]
  18. });
  19. }))
  20. .pipe(new QueryEvalStream());
  21. }
  22. module.exports = importBXRatings;
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...