Skip to content

Commit

Permalink
[tables] Migrate tables projects to use snippets extraction (#33187)
Browse files Browse the repository at this point in the history
### Packages impacted by this PR

- @azure/data-tables

### Issues associated with this PR

- #32416

### Describe the problem that is addressed by this PR

Updates all projects under `tables` to use snippets extraction.

### What are the possible designs available to address the problem? If
there are more than one possible design, why was the one in this PR
chosen?


### Are there test cases added in this PR? _(If not, why?)_


### Provide a list of related PRs _(if any)_


### Command used to generate this PR:**_(Applicable only to SDK release
request PRs)_

### Checklists
- [ ] Added impacted package name to the issue description
- [ ] Does this PR needs any fixes in the SDK Generator?** _(If so,
create an Issue in the
[Autorest/typescript](https://github.com/Azure/autorest.typescript)
repository and link it here)_
- [ ] Added a changelog (if necessary)

---------

Co-authored-by: Jeremy Meng <jeremy.ymeng@gmail.com>
  • Loading branch information
mpodwysocki and jeremymeng authored Feb 25, 2025
1 parent c94d74c commit aba6195
Show file tree
Hide file tree
Showing 37 changed files with 796 additions and 525 deletions.
3 changes: 3 additions & 0 deletions sdk/tables/data-tables/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
<!-- dev-tool snippets ignore -->

# Release History

## 13.3.1 (2025-01-14)

### Bugs Fixed

- Fix issue [#28624](https://github.com/Azure/azure-sdk-for-js/issues/28624) where request options were not available when submitting a transaction operation.
- Fix issue [#32239](https://github.com/Azure/azure-sdk-for-js/issues/32239) where Azurite emulator endpoint with a non-default port was treated as Cosmos endpoint.

Expand Down
74 changes: 38 additions & 36 deletions sdk/tables/data-tables/MigrationGuide.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<!-- dev-tool snippets ignore -->

# Guide for migrating to `@azure/data-tables` from `azure-storage`

This guide is intended to assist in the migration to `@azure/data-tables` from the legacy `azure-storage` package. It will focus on side-by-side comparisons for similar operations between the two packages.
Expand Down Expand Up @@ -69,7 +71,7 @@ const azure = require("azure-storage");
const tableService = azure.createTableService("<connection-string>");

const tableName = "<table-name>";
tableService.createTable(tableName, function() {
tableService.createTable(tableName, function () {
console.log(`Table created`);
});
```
Expand All @@ -83,7 +85,7 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";

const tableService = new TableServiceClient(
tablesEndpoint,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

// Creates the table with `tableName` if it doesn't exist
Expand All @@ -101,7 +103,7 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

// Creates the table with `tableName` if it doesn't exist
Expand All @@ -124,10 +126,10 @@ const task1 = {
PartitionKey: { _: "hometasks" },
RowKey: { _: "1" },
description: { _: "take out the trash" },
dueDate: { _: new Date(2015, 6, 20), $: "Edm.DateTime" }
dueDate: { _: new Date(2015, 6, 20), $: "Edm.DateTime" },
};

tableService.insertEntity(tableName, task1, function() {
tableService.insertEntity(tableName, task1, function () {
console.log("Entity inserted");
});
```
Expand All @@ -144,10 +146,10 @@ const task1 = {
PartitionKey: entGen.String("hometasks"),
RowKey: entGen.String("1"),
description: entGen.String("take out the trash"),
dueDate: entGen.DateTime(new Date(2015, 6, 20))
dueDate: entGen.DateTime(new Date(2015, 6, 20)),
};

tableService.insertEntity(tableName, task1, function() {
tableService.insertEntity(tableName, task1, function () {
console.log("Entity inserted");
});
```
Expand All @@ -162,15 +164,15 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

// Creates the table with `tableName` if it doesn't exist
const task1 = {
partitionKey: "hometasks",
rowKey: "1",
description: "take out the trash",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};

await tableClient.createEntity(task1);
Expand All @@ -186,14 +188,14 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

const task1: TableEntity = {
partitionKey: "hometasks",
rowKey: "1",
description: "take out the trash",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};

await tableClient.createEntity(task1);
Expand All @@ -210,7 +212,7 @@ const azure = require("azure-storage");
const tableService = azure.createTableService("<connection-string>");

const tableName = "<table-name>";
tableService.retrieveEntity(tableName, "hometasks", "1", function(error, result, response) {
tableService.retrieveEntity(tableName, "hometasks", "1", function (error, result, response) {
if (!error) {
// result contains the entity
console.log(result);
Expand All @@ -228,7 +230,7 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

const entity = await tableClient.getEntity("hometasks", "1");
Expand All @@ -248,7 +250,7 @@ const query = new azure.TableQuery().where("PartitionKey eq ?", "part2");
let entities = [];

function listEntities(query, continuationToken, callback) {
tableService.queryEntities(tableName, query, null, function(error, result) {
tableService.queryEntities(tableName, query, null, function (error, result) {
entities.push(result.entries);
const token = result.continuationToken;
if (token) {
Expand All @@ -260,7 +262,7 @@ function listEntities(query, continuationToken, callback) {
});
}

listEntities(query, null, function() {
listEntities(query, null, function () {
console.log(entities);
});
```
Expand All @@ -275,12 +277,12 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);
const partitionKey = "part2";

const entities = tableClient.listEntities({
queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` }
queryOptions: { filter: odata`PartitionKey eq ${partitionKey}` },
});

for await (const entity of entities) {
Expand All @@ -299,10 +301,10 @@ const tableService = azure.createTableService("<connection-string>");
const tableName = "<table-name>";
const task = {
PartitionKey: { _: "hometasks" },
RowKey: { _: "1" }
RowKey: { _: "1" },
};

tableService.deleteEntity(tableName, task, function(error, response) {
tableService.deleteEntity(tableName, task, function (error, response) {
if (!error) {
console.log("Entity deleted");
}
Expand All @@ -319,7 +321,7 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

await tableClient.deleteEntity("hometasks", "1");
Expand All @@ -340,21 +342,21 @@ const task1 = {
PartitionKey: { _: "hometasks" },
RowKey: { _: "1" },
description: { _: "Take out the trash" },
dueDate: { _: new Date(2015, 6, 20) }
dueDate: { _: new Date(2015, 6, 20) },
};
const task2 = {
PartitionKey: { _: "hometasks" },
RowKey: { _: "2" },
description: { _: "Wash the dishes" },
dueDate: { _: new Date(2015, 6, 20) }
dueDate: { _: new Date(2015, 6, 20) },
};

const batch = new azure.TableBatch();

batch.insertEntity(task1, { echoContent: true });
batch.insertEntity(task2, { echoContent: true });

tableService.executeBatch(tableName, batch, function(error, result, response) {
tableService.executeBatch(tableName, batch, function (error, result, response) {
if (!error) {
console.log("Batch completed");
}
Expand All @@ -371,25 +373,25 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

const task1 = {
partitionKey: "hometasks",
rowKey: "1",
description: "Take out the trash",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};
const task2 = {
partitionKey: "hometasks",
rowKey: "2",
description: "Wash the dishes",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};

const tableActions = [
["create", task1],
["create", task2]
["create", task2],
];

await tableClient.submitTransaction(tableActions);
Expand All @@ -406,20 +408,20 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

const task1 = {
partitionKey: "hometasks",
rowKey: "1",
description: "Take out the trash",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};
const task2 = {
partitionKey: "hometasks",
rowKey: "2",
description: "Wash the dishes",
dueDate: new Date(2015, 6, 20)
dueDate: new Date(2015, 6, 20),
};

const transaction = new TableTransaction();
Expand All @@ -439,19 +441,19 @@ const azure = require("azure-storage");
const tableService = azure.createTableService("<connection-string>");

const tableName = "<table-name>";
tableService.createTable(tableName, function() {
tableService.createTable(tableName, function () {
tableService.insertEntity(
tableName,
{ PartitionKey: "p1", RowKey: "r1", foo: "bar" },
function() {
function () {
tableService.insertEntity(
tableName,
{ PartitionKey: "p2", RowKey: "r2", foo: "baz" },
function() {
function () {
console.log("Inserted Entity");
}
},
);
}
},
);
});
```
Expand All @@ -466,7 +468,7 @@ const tablesEndpoint = "https://<account-name>.table.core.windows.net";
const tableClient = new TableClient(
tablesEndpoint,
tableName,
new AzureNamedKeyCredential("<accountName>", "<accountKey>")
new AzureNamedKeyCredential("<accountName>", "<accountKey>"),
);

await tableClient.createTable();
Expand Down
Loading

0 comments on commit aba6195

Please sign in to comment.