惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Y
Y Combinator Blog
美团技术团队
H
Hacker News: Front Page
Spread Privacy
Spread Privacy
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tenable Blog
Simon Willison's Weblog
Simon Willison's Weblog
T
The Exploit Database - CXSecurity.com
Cisco Talos Blog
Cisco Talos Blog
A
Arctic Wolf
C
CXSECURITY Database RSS Feed - CXSecurity.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
A
About on SuperTechFans
F
Fortinet All Blogs
量子位
GbyAI
GbyAI
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Hacker News
The Hacker News
AWS News Blog
AWS News Blog
Forbes - Security
Forbes - Security
Help Net Security
Help Net Security
I
InfoQ
有赞技术团队
有赞技术团队
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
Engineering at Meta
Engineering at Meta
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Webroot Blog
Webroot Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
博客园_首页
C
Check Point Blog
T
Troy Hunt's Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Latest news
Latest news
P
Proofpoint News Feed
Jina AI
Jina AI
Last Week in AI
Last Week in AI
Martin Fowler
Martin Fowler
雷峰网
雷峰网
博客园 - Franky
L
LangChain Blog
罗磊的独立博客
Blog — PlanetScale
Blog — PlanetScale
Google DeepMind News
Google DeepMind News
D
Docker
G
GRAHAM CLULEY
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC

Deno

Deno 2.8 | Deno Claw Patrol: an open-source security firewall for agents | Deno Fresh 2.3: Zero JS by default, View Transitions, and Temporal support | Deno Deno 2.7: Temporal API, Windows ARM, and npm overrides | Deno Build a dinosaur runner game with Deno, pt. 6 | Deno Build a dinosaur runner game with Deno, pt. 5 | Deno Deno Deploy is Generally Available | Deno Introducing Deno Sandbox | Deno Build a dinosaur runner game with Deno, pt. 4 | Deno Build a dinosaur runner game with Deno, pt. 3 | Deno Build a dinosaur runner game with Deno, pt. 2 | Deno React / Next.js Denial-of-Service Vulnerability: Deno Deploy users protected | Deno Deno 2.6: dx is the new npx | Deno Build a dinosaur runner game with Deno, pt. 1 | Deno React Server Functions / Next.js Vulnerability: Deno Deploy users protected | Deno My highlights from the new Deno Deploy | Deno Deno's Other Open Source Projects | Deno How Deno protects against npm exploits | Deno Help Us Raise $200k to Free JavaScript from Oracle | Deno Deno 2.5: Permissions in the config file | Deno Fresh 2.0 Graduates to Beta, Adds Vite Support | Deno Deno 2.4: deno bundle is back | Deno JavaScript™ Trademark Update | Deno What's coming to JavaScript | Deno A brief history of JavaScript | Deno Reports of Deno's Demise Have Been Greatly Exaggerated | Deno An Update on Fresh | Deno How Plaid migrated 100 services to a new database platform 5x faster with Deno | Deno Deno 2.3: Improved deno compile, local npm packages, and more | Deno Add JSR packages with pnpm and Yarn | Deno Zero-config Debugging with Deno and OpenTelemetry | Deno Exploring Art with TypeScript, Jupyter, Polars, and Observable Plot | Deno Deno v Oracle Update 3: Fighting the JavaScript Trademark | Deno Build a custom RAG AI agent in TypeScript and Jupyter | Deno How to get deep traces in your Node.js backend with OTel and Deno | Deno toranoana.deno #20 登録受付中(2025年3月14日) | Deno Node just added TypeScript support. What does that mean for Deno? | Deno The Dino 🦕, the Llama 🦙, and the Whale 🐋 | Deno Publish a lint rule, get a prize | Deno Deno 2.2: OpenTelemetry, Lint Plugins, node:sqlite | Deno If you're not using npm specifiers, you're doing it wrong | Deno How Deno's documentation is evolving | Deno Oracle justified its JavaScript trademark with Node.js—now it wants that ignored | Deno Introducing the JSR open governance board | Deno Intro to Wasm in Deno | Deno Announcing OpenAI on JSR | Deno Deno in 2024 | Deno Goodbye WinterCG, welcome WinterTC | Deno Build a SolidJS app with Deno | Deno Run your Next.js SSR app on Deno Deploy | Deno Solve Advent of Code 2024 with Deno and Win Prizes! | Deno Deno v. Oracle: Canceling the JavaScript Trademark | Deno Deno 2.1: Wasm Imports and other enhancements | Deno Build a Typesafe API with tRPC and Deno | Deno Self-contained Executable Programs with Deno Compile | Deno Build a Database App with Drizzle ORM and Deno | Deno Introducing your new JavaScript package manager: Deno | Deno Announcing Growthbook on JSR | Deno Build an Astro site with Deno | Deno How to convert CommonJS to ESM | Deno Announcing Deno 2 | Deno The Final Touches: What’s New In v2.0.0-rc.10 | Deno Announcing Stable V8 Bindings for Rust | Deno Deno 2.0 Release Candidate | Deno Secure, efficient private npm registries with Cloudsmith and Deno | Deno Painting the Plane as We Fly It: Designing JSR | Deno Introducing Web Cache API support on Deno Deploy | Deno Deno 1.46: The Last 1.x Release | Deno Protect your cloud spend with new Deno Deploy spend limits | Deno What we got wrong about HTTP imports | Deno Benchmarking AWS Lambda Cold Starts Across JavaScript Runtimes | Deno Announcing Supabase on JSR | Deno Deno 1.45: Workspace and Monorepo Support | Deno Introducing KV Backup for Deno Subhosting | Deno A Gentle Intro to TypeScript | Deno Announcing Hono on JSR | Deno How We Made the Deno Language Server Ten Times Faster | Deno How the Guardian uses Deno to audit accessibility and performance across their 2.7 million articles | Deno Introducing More Flexible Domain Association for Deno Subhosting | Deno The stabilization process of the Standard Library has begun | Deno Deno 1.44: Private npm registries, improved Node.js compat, and performance boosts | Deno How we built a secure, performant, multi-tenant cloud platform to run untrusted code | Deno The Deno Standard Library is now available on JSR | Deno How to document your JavaScript package | Deno Your Low Code Solution Needs an Escape Hatch | Deno Deno 1.43: Improved Language Server performance | Deno How Slack used Deno to save months of engineering effort in launching their new platform | Deno JSR Is Not Another Package Manager | Deno Announcing the Hookdeck SDK on JSR | Deno Announcing the Neon Serverless Driver on JSR | Deno An intro to TSConfig for JavaScript Developers | Deno How we built JSR | Deno How Netlify used Deno Subhosting to build a successful edge functions product | Deno Introducing Simpler Project Creation in Deno Deploy | Deno Deno 1.42: Better dependency management with JSR | Deno Introducing deployctl, the command line interface for Deno Deploy | Deno Introducing JSR - the JavaScript Registry | Deno How to add Monaco to a Next.js app and securely run untrusted user code | Deno Survey Results and Roadmap | Deno Deno 1.41: smaller deno compile binaries | Deno
Persist Data in Deno with npm using Prisma, Mongoose, Apollo, and more. | Deno
Andy Jiang · 2022-11-15 · via Deno

Persistent data is essential to building modern web apps. We need it to save user information, bill customers, and more. Now you can use your favorite data storage technologies—Prisma, Mongoose, MySQL, and more—with npm and Deno.

This blog post will show you how to quickly get started with these npm modules with Deno:

  • Prisma
  • Mongoose
  • Apollo

Check out our Manual for more How To guides on getting started with data persistence npm modules.

Safer data persistence with Deno

Supply chain attacks are a known security issue on npm. Node installs and runs npm modules with access to everything by default, making it easier for a single malicious dependency to quietly compromise millions of end users.

Data storage is at even greater risk to supply chain attacks, as production data is sensitive, necessary to run a business, and can be accessed through environment variables.

Deno’s opt-in permission model ensures you know what your dependencies require access to. The permission system is granular enough for you to grant access to environment variables, the filesystem, and even FFI.

Prisma

Prisma, a modern ORM with best-in-class developer experience, has been one of our top requested modules. Here’s a quick guide to getting started with Prisma and Deno.

This next section will show you how to quickly connect Prisma with Deno.

View source here or follow the video guide on our YouTube channel!

Setup the application

Let’s create the folder deno-prisma and navigate there.

mkdir deno-prisma & cd deno-prisma

Then, let’s run prisma init with Deno:

deno run --allow-read --allow-env --allow-write npm:prisma@^4.5 init

This will generate prisma/schema.prisma. Let’s update it with the following:

generator client {
  provider = "prisma-client-js"
  previewFeatures = ["deno"]
  output = "../generated/client"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Dinosaur {
  id          Int     @id @default(autoincrement())
  name        String  @unique
  description String
}

Prisma should also have generated a .env file with DATABASE_URL. Let’s assign DATABASE_URL to a PostreSQL connection string. In this example, we’ll use a free PostgreSQL database from Supabase.

After you have updated your .env file, let’s create the database schema in Prisma:

deno run npm:prisma@^4.5 db push

After that’s complete, we’ll need to generate a Prisma client for Data Proxy:

deno run npm:prisma@^4.5 generate --data-proxy

Setup Prisma Data Platform

In order to use Prisma Data Platform, we’ll have to create and connect a GitHub repo. So let’s initialize the repository, create a new GitHub repo, add the remote origin, and push the repo.

After you’ve done that, sign up for a free Prisma Data Platform account.

Click New Project and select Import a Prisma Repository.

It’ll ask for a PostgreSQL connection string, which you have in your .env. Paste it here. Then click Create Project.

You’ll receive a new connection string that begins with prisma://. Let’s grab that and assign it to DATABASE_URL in your .env file, replacing your PostgreSQL string from Supabase.

Using Prisma and PrismaClient

Now, you’ll be able to import Prisma and PrismaClient into your Deno project:

import { Prisma, PrismaClient } from "../generated/client/deno/edge.ts";

From here, you can seed your database, query your data, and more.

Check out our more in-depth How To guide with Prisma or learn how to deploy Prisma on Deno Deploy.

Mongoose

Mongoose is a popular, schema-based library that models data for MongoDB. Here is a quick guide to getting started.

View source here or follow our video guide on YouTube.

Define a model

Let’s define a model in Mongoose. In a new file Dinosaur.ts, let’s add:

import { model, Schema } from "npm:mongoose@^6.7";


const dinosaurSchema = new Schema({
  name: { type: String, unique: true },
  description: String,
  createdAt: { type: Date, default: Date.now },
  updatedAt: { type: Date, default: Date.now },
});


dinosaurSchema.path("name").required(true, "Dinosaur name cannot be blank.");
dinosaurSchema.path("description").required(
  true,
  "Dinosaur description cannot be blank.",
);


export default model("Dinosaur", dinosaurSchema);

Create a new Dinosaur

Let’s create a new file, main.ts, that will:

  • connect to MongoDB
  • create a new Dinosaur
  • retrieve a dinosaur with name “Deno”
  • console.log the retrieved dinosaur
import mongoose from "npm:mongoose@^6.7";
import Dinosaur from "./model/Dinosaur.ts";

await mongoose.connect("mongodb://localhost:27017");


const deno = new Dinosaur({
  name: "Deno",
  description: "The fastest dinosaur ever lived.",
});


await deno.save();


const denoFromMongoDb = await Dinosaur.findOne({ name: "Deno" });
console.log(
  `Finding Deno in MongoDB -- \n  ${denoFromMongoDb.name}: ${denoFromMongoDb.description}`,
);

Your output should be:

Finding Deno in MongoDB --
  Deno: The fastest dinosaur ever lived.

Success!

Check out our more in-depth How To guide with Mongoose.

Apollo

Apollo is a GraphQL server you can setup in minutes and use with your existing data source (or REST API). You can connect any GraphQL client to it to access the data and take advantage of typechecking and efficient fetching.

Let’s get a simple Apollo server up and running that will allow us to query some local data. We’re only going to need three files for this:

  1. schema.ts to set up our data model
  2. resolvers.ts to set up how we’re going to populate the data fields in our schema
  3. Our main.ts where the server is going to launch

We’ll start by creating them:

touch schema.ts resolvers.ts main.ts

Let’s go through setting up each.

View source here.

Define our data with schema.ts

Our schema.ts file describes our data. In this case, our data is a list of dinosaurs. We want our users to be able to get the name and a short description of each dino. In GraphQL language, this means that Dinosaur is our type, and name and description are our fields. We can also define the data type for each field. In this case, both are strings.

This is also where we describe the queries we allow for our data, using the special Query type in GraphQL. We have two queries:

  • dinosaurs which gets a list of all dinosaurs
  • dinosaur which takes in the name of a dinosaur as an argument and returns information about that one type of dinosaur.

We’re going to export all this within our typeDefs type definitions, variable:

export const typeDefs = `
  type Dinosaur {
    name: String
    description: String
  }

  type Query {
    dinosaurs: [Dinosaur]
        dinosaur(name: String): Dinosaur
  }
`;

If we wanted to write data, this is also where we would describe the Mutation to do so. Mutations are how you write data with GraphQL. Because we are using a static dataset here, we won’t be writing anything.

Populate data in resolvers.ts

A resolver is responsible for populating the data for each query. Here we have our list of dinosaurs and all the resolver is going to do is either a) pass that entire list to the client if the user requests the dinosaurs query, or pass just one if the user requests the dinosaur query.

const dinosaurs = [
  {
    name: "Aardonyx",
    description: "An early stage in the evolution of sauropods.",
  },
  {
    name: "Abelisaurus",
    description: '"Abel\'s lizard" has been reconstructed from a single skull.',
  },
];

export const resolvers = {
  Query: {
    dinosaurs: () => dinosaurs,
    dinosaur: (_: any, args: any) => {
      return dinosaurs.find((dinosaur) => dinosaur.name === args.name);
    },
  },
};

With the later, we pass the arguments from the client into a function to match the name to a name in our dataset.

Set up main.ts

In our main.ts we’re going to import the ApolloServer as well as graphql and our typeDefs from the schema and our resolvers:

import { ApolloServer } from "npm:@apollo/server@^4.1";
import { startStandaloneServer } from "npm:@apollo/server@^4.1/standalone";
import { graphql } from "npm:graphql@^16.6";
import { typeDefs } from "./schema.ts";
import { resolvers } from "./resolvers.ts";

const server = new ApolloServer({
  typeDefs,
  resolvers,
});

const { url } = await startStandaloneServer(server, {
  listen: { port: 8000 },
});

console.log(`Server running on: ${url}`);

We pass our typeDefs and resolvers to ApolloServer to spool up a new server. Finally, startStandaloneServer is a helper function to get the server up and running quickly.

Running the server

All that is left to do now is run the server:

deno run --allow-net --allow-read --allow-env main.ts

You should see Server running on: 127.0.0.1:8000 in your terminal. If you go to that address you will see the Apollo sandbox where we can enter our dinosaurs query:

query {
  dinosaurs {
    name
    description
  }
}

This will return our dataset:

{
  "data": {
    "dinosaurs": [
      {
        "name": "Aardonyx",
        "description": "An early stage in the evolution of sauropods."
      },
      {
        "name": "Abelisaurus",
        "description": "\"Abel's lizard\" has been reconstructed from a single skull."
      }
    ]
  }
}

Or if we want just one dinosaur:

query {
  dinosaur(name:"Aardonyx") {
    name
    description
  }
}

Which returns:

{
  "data": {
    "dinosaur": {
      "name": "Aardonyx",
      "description": "An early stage in the evolution of sauropods."
    }
  }
}

Awesome!

Check out our more in-depth How To guide with Apollo.

What’s next?

This blog post showed how to get started with Prisma, Mongoose, and Apollo. We also have How To guides for other data persistence npm modules such as PlanetScale, Redis, and MySQL2, and will continue to add more.

Stuck? Get help on our Discord.