-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
workingWithInt64.js
53 lines (41 loc) · 1.43 KB
/
workingWithInt64.js
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
48
49
50
51
52
53
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
/**
* This sample demonstrates how to create and consume Int64 values
*
* @summary creates and works with an entity containing an Int64 value
*/
const { TableClient, AzureNamedKeyCredential } = require("@azure/data-tables");
// Load the .env file if it exists
const dotenv = require("dotenv");
dotenv.config();
const tablesUrl = process.env["TABLES_URL"] || "";
const accountName = process.env["ACCOUNT_NAME"] || "";
const accountKey = process.env["ACCOUNT_KEY"] || "";
async function workingWithInt64() {
console.log("working with Int64 sample");
const client = new TableClient(
tablesUrl,
"testInt64",
new AzureNamedKeyCredential(accountName, accountKey)
);
await client.createTable();
await client.createEntity({
partitionKey: "p1",
rowKey: "1",
// To work with Int64 we need to use an object that includes
// the value as a string and a notation of the type, in this case Int64
foo: { value: "12345", type: "Int64" }
});
const entity = await client.getEntity("p1", "1", { disableTypeConversion: true });
// In order to do arithmetic operations with Int64 you need to use
// bigint or a third party library such as 'long'
console.log(entity);
await client.deleteTable();
}
async function main() {
await workingWithInt64();
}
main().catch((err) => {
console.error("The sample encountered an error:", err);
});