@grammyjs/storage-prisma
Advanced tools
Comparing version 0.0.2 to 2.0.0
{ | ||
"name": "@grammyjs/storage-prisma", | ||
"version": "0.0.2", | ||
"version": "2.0.0", | ||
"private": false, | ||
"description": "Prisma storage for grammY.", | ||
"description": "Prisma storage for grammY", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"files": [ | ||
"README.md", | ||
"dist", | ||
"package.json", | ||
"LICENSE" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/grammyjs/storages.git" | ||
}, | ||
"author": "Dani Haro <daniharopadul@gmail.com>", | ||
"license": "MIT" | ||
} | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/grammyjs/storages/issues" | ||
}, | ||
"homepage": "https://github.com/grammyjs/storages/tree/main/packages/typeorm#readme", | ||
"devDependencies": { | ||
"@grammyjs/storage-utils": "1.0.3", | ||
"@prisma/client": "^4.1.0", | ||
"grammy": "^1.5.4", | ||
"prisma": "^4.1.0", | ||
"vite": "^2.9.8", | ||
"vitest": "^0.16.0" | ||
}, | ||
"scripts": { | ||
"test:deno": "echo \"Error: no tests found\"", | ||
"test": "npx prisma generate; npx prisma db push; vitest", | ||
"start": "node dist/index.js", | ||
"dev": "npx prisma generate & npx prisma db push & nodemon", | ||
"debug": "node --inspect=0.0.0.0:9229 --nolazy ./dist/index.js", | ||
"prebuild": "rimraf dist", | ||
"build": "tsc -p tsconfig.build.json", | ||
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s --commit-path ." | ||
} | ||
} |
@@ -1,1 +0,79 @@ | ||
test | ||
# Prisma storage adapter for grammY | ||
Storage adapter that can be used to [store your session data](https://grammy.dev/plugins/session.html) with [Prisma](https://www.prisma.io/) when using sessions. | ||
## Installation | ||
```bash | ||
npm install @grammyjs/storage-prisma --save | ||
``` | ||
## Usage | ||
You can check the [examples](https://github.com/grammyjs/storages/tree/main/packages/prisma/examples) folder, or simply use followed code: | ||
Implement the Session model in your Prisma schema: | ||
```prisma | ||
model Session { | ||
id Int @id @default(autoincrement()) | ||
key String @unique | ||
value String | ||
} | ||
``` | ||
> The `id` field is not needed for this adapter to work. | ||
> | ||
> The only restriction is that `key` must be a `String` index, either by | ||
> adding the `@unique` keyword or the `@id` keyword, and `value` must be a `String`. | ||
Generate Prisma client using the terminal: | ||
```bash | ||
npx prisma generate | ||
``` | ||
[Migrate](https://www.prisma.io/docs/concepts/components/prisma-migrate) the schema changes to your database: | ||
```bash | ||
npx prisma db push | ||
# or | ||
npx prisma migrate dev | ||
``` | ||
Create bot and pass adapter as storage: | ||
```ts | ||
import { Bot, Context, session, SessionFlavor } from "grammy"; | ||
import { PrismaAdapter } from "@grammyjs/storage-prisma"; | ||
import { PrismaClient } from "@prisma/client"; | ||
// Create Prisma client | ||
const prisma = new PrismaClient(); | ||
// write session types | ||
interface SessionData { | ||
counter: number; | ||
} | ||
// create context for grammy instance | ||
type MyContext = Context & SessionFlavor<SessionData>; | ||
// Create bot and register session middleware | ||
async function bootstrap() { | ||
const bot = new Bot<MyContext>(""); | ||
bot.use( | ||
session({ | ||
initial: () => ({ counter: 0 }), | ||
storage: new PrismaAdapter(prisma.session), | ||
}) | ||
); | ||
// Register your usual middleware, and start the bot | ||
bot.command("stats", (ctx) => | ||
ctx.reply(`Already got ${ctx.session.counter} photos!`) | ||
); | ||
bot.on(":photo", (ctx) => ctx.session.counter++); | ||
bot.start(); | ||
} | ||
``` |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No bug tracker
MaintenancePackage does not have a linked bug tracker in package.json.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
8316
7
79
0
0
80
0
6