当前位置: 首页 > article >正文

docker安装postgres扩展age以及使用nodejs连接

docker安装postgres扩展age以及使用nodejs连接

官网: https://age.apache.org/age-manual/master/advanced/plpgsql.html

GitHub: https://github.com/apache/age/blob/master/README.md

docker pull apache/age

docker run
–name myPostgresDb
-p 5455:5432
-e POSTGRES_USER=postgresUser
-e POSTGRES_PASSWORD=postgresPW
-e POSTGRES_DB=postgresDB
-d
apache/age

LOAD ‘age’;

SET search_path = ag_catalog, “$user”, public; # 简化查询,设置用户public,后面对该用户进行授权

grant usage on schema ag_catelog to db_user(public) # 授权用户 public

新开一个窗口

docker exec -it age psql -d postgresDB -U PostgresUser

ln -s /usr/lib/postgresql/16/lib/age.so /usr/lib/postgresql/16/lib/plugins/age.so # 创建符号链接,允许非超级用户加载age库

这里替换为你自己的版本,以及mkdir一下plugins目录

使用age的nodejs-sdk连接,没有npm包。整个下载下来copy到项目中,可以link,也可以直接引入。

pnpm install pg config debug

config/default.json

{
  "age":{
      "user": "postgresUser",
      "host": "127.0.0.1",
      "database": "postgresDB",
      "password": "postgresPW",
      "port": "5455"
  }
}
import pg from 'pg'
import config from "config"
import debug from 'debug'
import { setAGETypes } from '../nodejs-pg-age/dist/index.js'
const { types, Client } = pg
const dbConfig = config['age']

function createDebug(moduleName) {
  return debug('age').extend(moduleName);
}

async function main () {
  const debug = createDebug('main')
  const client = new Client(dbConfig)
  await client.connect()
  await setAGETypes(client, types)
  let ret = await client.query(`SELECT * 
FROM cypher('graph_name', $$
    MATCH (a:label), (b:label)
    WHERE a.property = 'Node A' AND b.property = 'Node B'
    CREATE (a)-[e:RELTYPE {property:a.property + '<->' + b.property}]->(b)
    RETURN e
$$) as (e agtype);`)
    if (ret?.rowCount > 0) {
      debug(ret.rows);
    }
}

main()
  .then((data) => console.log(data))
  .catch(err => console.error(err))
{
	"name": "age-crud",
	"version": "1.0.0",
	"description": "",
	"main": "./src/index.js",
	"author": "hjj",
	"license": "ISC",
	"type": "module",
	"scripts": {
		"start": "DEBUG=age:* DEBUG_DEPTH=5 node ./src/index.js"
	},
	"dependencies": {
		"config": "^3.3.12",
		"debug": "^4.3.7",
		"pg": "^8.12.0"
	}
}

pgadmin4连接


http://www.kler.cn/news/365164.html

相关文章:

  • 《在1688的数字海洋中,如何用API网罗一家店铺的所有商品?》
  • 金融工程--pine-script 入门
  • ResNet-RS 乳腺癌识别
  • Detectron2和LSTM进行人体动作识别
  • 精益思维在新能源汽车研发中的应用体现
  • 信息安全工程师(55)网络安全漏洞概述
  • TCP单包数据大于1460字节会被拆包的问题
  • Python项目引入其他项目作为子模块
  • 漏洞技术分析实践_整数溢出
  • “智能科研写作:结合AI与ChatGPT提升SCI论文和基金申请质量“
  • 微信小程序实现canvas电子签名
  • 开源进销存软件如何助力中小企业数字化转型?
  • [论文阅读]TELeR: A General Taxonomy of LLM Prompts for Benchmarking Complex Tasks
  • 二分查找_在排序数组中查找元素的第一个和最后一个位置
  • 测试WIFI和以太网的TCP带宽、UDP带宽和丢包率、延时
  • 揭开C++ STL的神秘面纱之string:提升编程效率的秘密武器
  • 没错,Go 语言的函数参数没有引用传递方式
  • 考研读研生存指南,注意事项
  • useEffect简单介绍
  • java -jar启动 报错: Error: Unable to access jarfile
  • NVR小程序接入平台/设备EasyNVR多品牌NVR管理工具/设备的多维拓展与灵活应用
  • 基于SSM+微信小程序的家政服务管理系统(家政2)
  • 批量归一化(Batch Normalization)
  • 混个1024勋章
  • [笔记] 关于CreateProcessWithLogonW函数创建进程
  • Linux系统