Skip to content

Commit

Permalink
Merge branch 'main' into feat/azure-storage-blob
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed Feb 27, 2023
2 parents e944590 + 47c5e66 commit b339f66
Show file tree
Hide file tree
Showing 9 changed files with 1,787 additions and 271 deletions.
54 changes: 47 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,50 @@ const storage = createStorage({
- `storage`: The name of the table to read from. It defaults to `storage`.
- `boostCache`: Whether to enable cached queries: see [docs](https://planetscale.com/docs/concepts/query-caching-with-planetscale-boost#using-cached-queries-in-your-application).

### `azure-storage-blob`
### `mongodb`

⚠️ This driver is currently not compatible with edge workers like Cloudflare Workers or Vercel Edge Functions. There may be a http based driver in the future.
Store data in a MongoDB [mongodb](https://www.npmjs.com/package/mongodb) using [Node.js mongodb package](https://www.npmjs.com/package/mongodb)

This driver stores KV information in a MongoDB collection with a separate document for each key value pair.

To use it, you will need to install `mongodb` in your project:

```json
{
"dependencies": {
"mongodb": "^5.0.1"
}
}
```

Usage:

```js
import { createStorage } from "unstorage";
import mongodbDriver from "unstorage/drivers/mongodb";

const storage = createStorage({
driver: mongodbDriver({
connectionString: "CONNECTION_STRING",
databaseName: "test",
collectionName: "test",
}),
});
```

**Authentication:**

The driver supports the following authentication methods:

- **`connectionString`**: The MongoDB connection string. This is the only way to authenticate.

**Options:**

- **`connectionString`** (required): The connection string to use to connect to the MongoDB database. It should be in the format `mongodb://<username>:<password>@<host>:<port>/<database>`.
- `databaseName`: The name of the database to use. Defaults to `unstorage`.
- `collectionName`: The name of the collection to use. Defaults to `unstorage`.

## `azure-storage-blob`

Store data in a Azure blob storage [storage-blob](https://github.com/Azure/azure-sdk-for-js/tree/main/sdk/storage/storage-blob).

Expand All @@ -646,11 +687,10 @@ Please make sure that the container you want to use exists in your storage accou
```js
import { createStorage } from "unstorage";
import azureStorageBlobDriver from "unstorage/drivers/azure-storage-blob";

const storage = createStorage({
driver: azureStorageBlobDriver({
accountName: "myazurestorageaccount",
}),
driver: azureStorageBlobDriver({
accountName: "myazurestorageaccount",
}),
});
```

Expand All @@ -659,7 +699,7 @@ const storage = createStorage({
The driver supports the following authentication methods:

- **`DefaultAzureCredential`**: This is the recommended way to authenticate. It will use managed identity or environment variables to authenticate the request. It will also work in a local environment by trying to use Azure CLI or Azure PowerShell to authenticate. <br>
⚠️ Make sure that your Managed Identity or personal account has the `Storage Blob Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
⚠️ Make sure that your Managed Identity or personal account has the `Storage Blob Data Contributor` role assigned to it, even if you already are `Contributor` or `Owner` on the storage account.
- **`AzureNamedKeyCredential`** (only available in Node.js runtime): This will use the `accountName` and `accountKey` to authenticate the request.
- **`AzureSASCredential`**: This will use the `accountName` and `sasToken` to authenticate the request.
- **connection string** (only available in Node.js runtime): This will use the `connectionString` to authenticate the request. This is not recommended as it will expose your account key in plain text.
Expand Down
39 changes: 21 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
"drivers"
],
"scripts": {
"azurite-blob-storage": "azurite-blob --silent",
"build": "unbuild",
"demo": "vite demo",
"dev": "vitest",
"lint": "eslint --ext .ts . && prettier -c src test demo",
"prepack": "pnpm build",
"release": "pnpm test && changelogen --release && git push --follow-tags && pnpm publish",
"test": "pnpm lint && vitest run --coverage",
"azurite-blob-storage": "azurite-blob --silent",
"unstorage": "pnpm jiti src/cli"
},
"dependencies": {
Expand All @@ -46,45 +46,48 @@
"destr": "^1.2.2",
"h3": "^1.5.0",
"ioredis": "^5.3.1",
"listhen": "^1.0.2",
"lru-cache": "^7.16.0",
"listhen": "^1.0.3",
"lru-cache": "^7.17.0",
"mri": "^1.2.0",
"node-fetch-native": "^1.0.2",
"ofetch": "^1.0.1",
"ufo": "^1.1.0"
},
"optionalDependencies": {
"@planetscale/database": "^1.5.0",
"@azure/identity": "^3.1.3",
"@azure/storage-blob": "^12.12.0"
},
"devDependencies": {
"@azure/identity": "^3.1.3",
"@azure/storage-blob": "^12.12.0",
"azurite": "^3.21.0",
"@cloudflare/workers-types": "^4.20230214.0",
"@planetscale/database": "^1.5.0",
"@types/jsdom": "^21.1.0",
"@types/mri": "^1.1.1",
"@types/node": "^18.13.0",
"@types/node": "^18.14.1",
"@vitejs/plugin-vue": "^4.0.0",
"@vitest/coverage-c8": "^0.28.5",
"@vitest/coverage-c8": "^0.29.1",
"@vue/compiler-sfc": "^3.2.47",
"azurite": "^3.21.0",
"c8": "^7.13.0",
"changelogen": "^0.4.1",
"eslint": "^8.34.0",
"eslint-config-unjs": "^0.1.0",
"jiti": "^1.17.0",
"ioredis-mock": "^8.2.6",
"jiti": "^1.17.1",
"jsdom": "^21.1.0",
"monaco-editor": "^0.35.0",
"msw": "^1.0.1",
"monaco-editor": "^0.36.0",
"mongodb": "^5.0.1",
"mongodb-memory-server": "^8.11.4",
"msw": "^1.1.0",
"prettier": "^2.8.4",
"types-cloudflare-worker": "^1.2.0",
"typescript": "^4.9.5",
"unbuild": "^1.1.1",
"vite": "^4.1.1",
"vitest": "^0.28.5",
"unbuild": "^1.1.2",
"vite": "^4.1.4",
"vitest": "^0.29.1",
"vue": "^3.2.47"
},
"packageManager": "pnpm@7.27.0"
"optionalDependencies": {
"@azure/identity": "^3.1.3",
"@azure/storage-blob": "^12.12.0",
"@planetscale/database": "^1.5.0"
},
"packageManager": "pnpm@7.28.0"
}
Loading

0 comments on commit b339f66

Please sign in to comment.