Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

nw-db

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nw-db

nw-db for Laf

  • 0.0.7
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

依赖介绍

本依赖仅适用于 Laf!相同 K8S 集群下可以跨应用操作数据库。

如:laf.dev 的不同账号或者不同应用可以互相操作数据库

laf.dev 和 laf.run 的无法互通,他们不在一个 K8S 集群内!

使用方法

安装依赖

左下角添加 NPM 依赖,搜索 nw-db,并安装

获取原应用的数据库链接地址

新建一个云函数,打印数据库链接地址

console.log(process.env.DB_URI)

其他应用调用示例代码

import cloud from '@lafjs/cloud'
import { createDb, createMongo } from 'nw-db'

export default async function (ctx: FunctionContext) {
  // 填入上一步中获取的 uri 地址
  const uri = 'mongodb://sc64px:EuV9oK1F036zf89vGg8wb6WdqHqk7NiHN2xCig1iKB1y6vc5uoJSD7pbIIxk6h0t@mongodb-0.mongo.laf-system.svc.cluster.local:27017/sc64px?authSource=sc64px&replicaSet=rs0&w=majority' 

  const db = cloud.database()
  const res = await db.collection("user").get()
  console.log(res)

  const db2 = await createDb(uri)
  const res2 = await db2.collection("user").get()
  console.log(res2)

  const { db, client } = await createMongo(uri)
  const res3 = await db.collection("user").findOne()
  console.log(res3)
}

FAQs

Package last updated on 15 Aug 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc