Created
April 12, 2019 19:38
-
-
Save plavjanik/12f0c95e9bc1281a22977accba1b9895 to your computer and use it in GitHub Desktop.
VSAM example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const os = require('os'); | |
const vsam = require('vsam.js'); | |
const vsamDsn = os.userInfo().username + '.TEST.VSAM.KSDS'; | |
const schema = { | |
key: { | |
type: "string", | |
maxLength: 5 | |
}, | |
name: { | |
type: "string", | |
maxLength: 10 | |
}, | |
gender: { | |
type: "string", | |
maxLength: 10 | |
} | |
}; | |
var file; | |
if (!vsam.exist(vsamDsn)) { | |
console.log(`${vsamDsn} does not exist`); | |
file = vsam.allocSync(vsamDsn, schema); | |
console.log(`${vsamDsn} allocated`); | |
} | |
else { | |
file = vsam.openSync(vsamDsn, schema); | |
} | |
file.read((record, err) => { | |
if (record) { | |
console.log("Record read", record); | |
file.close((err) => { | |
console.log("Error", err); | |
}); | |
} else { | |
console.log("Creating record"); | |
rec = { | |
key: "00001", | |
name: "Petr", | |
gender: "male" | |
}; | |
file.write(rec, (err) => { | |
if (err) { | |
console.log("Error", err); | |
} | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment