-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
2,880 additions
and
2,724 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export default { | ||
endpoint: "https://replidraw.documents.azure.com:443/", | ||
key: "Wl0K3w4jCedslIsKlwsgXGOOaiiPz2uwM9HrmaSkkrrjnn3eFrSiy9zAZWXU3btml5gbis3B2pcRHhvJg0y0tg==", | ||
databaseId: "replidraw", | ||
containerId: "c1", | ||
partitionKey: { kind: "Hash", paths: ["/partition"] } | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
|
||
import config from './config'; | ||
import {CosmosClient} from '@azure/cosmos'; | ||
|
||
/* | ||
// This script ensures that the database is setup and populated correctly | ||
*/ | ||
async function create(client, databaseId, containerId) { | ||
const partitionKey = config.partitionKey; | ||
|
||
/** | ||
* Create the database if it does not exist | ||
*/ | ||
const { database } = await client.databases.createIfNotExists({ | ||
id: databaseId | ||
}); | ||
console.log(`Created database:\n${database.id}\n`); | ||
|
||
/** | ||
* Create the container if it does not exist | ||
*/ | ||
const { container } = await client | ||
.database(databaseId) | ||
.containers.createIfNotExists( | ||
{ id: containerId, partitionKey }, | ||
{ offerThroughput: 400 } | ||
); | ||
|
||
console.log(`Created container:\n${container.id}\n`); | ||
} | ||
|
||
export default {create}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { CosmosClient } from '@azure/cosmos'; | ||
import config from './config'; | ||
import dbContext from './databaseContext'; | ||
|
||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
const uniqueID = Math.random().toString(36).substr(2); | ||
|
||
const { endpoint, key, databaseId, containerId } = config; | ||
const client = new CosmosClient({ endpoint, key }); | ||
const database = client.database(databaseId); | ||
const container = database.container(containerId); | ||
|
||
console.time('Processing push: ' + uniqueID); | ||
|
||
const newItem = { | ||
id: Math.random().toString(36).substr(2), | ||
content: `{ | ||
"ref": Ref(Collection("objects"), "290282750093558285"), | ||
"ts": 1613670707753000, | ||
"data": { | ||
"width": 163, | ||
"height": 84, | ||
"rotate": 0, | ||
"strokeWidth": 0, | ||
"fill": "pink", | ||
"radius": "0", | ||
"blendMode": "normal", | ||
"type": "rectangle", | ||
"x": 190, | ||
"y": 334 | ||
} | ||
}`, | ||
}; | ||
const { resource: createdItem } = await container.items.create(newItem); | ||
console.timeEnd('Processing push: ' + uniqueID); | ||
console.log(`\r\nCreated new item: ${createdItem.id}\r\n`); | ||
|
||
|
||
res.status(200).json({}); | ||
}; |
Oops, something went wrong.