node-oracledb typeorm 集成试用

主要是测试下typeorm与node-oracledb thin 模式的集成

环境准备

  • docker-compose 文件
version: '3'
services:
   db:
      image: gvenzl/oracle-xe:21.3.0-slim
      ports:
         - "1521:1521"
      environment:
       - ORACLE_PASSWORD=Ccda5662E
       - APP_USER=dalong
       - APP_USER_PASSWORD=Ccda5662E

typeorm 集成

  • entity.js
const EntitySchema = require("typeorm").EntitySchema
module.exports = new EntitySchema({
    name: "sensor", // Will use table name `category` as default behaviour.
    tableName: "sensor", // Optional: Provide `tableName` property to override the default behaviour for table name.
    columns: {
        id: {
            primary: true,
            type: "varchar",
        },
        name: {
            type: "varchar",
        },
        address: {
            type: "varchar"
        }
    }
})
  • datasource.js
const typeorm = require("typeorm")
 
/**
 * data store operation for sensor data
 */
const dataSource = new typeorm.DataSource({
    type: "oracle",
    username: "dalong",
    password: "Ccda5662E",
    connectString:"127.0.0.1/XEPDB1",
    synchronize: true,
    entities: [require("./entity")],
})
 
module.exports = dataSource
  • index.js
const dataSource = require('./datasource')
async function run() {
    const dataSourceInstance = await dataSource.initialize()
    if(dataSourceInstance.isInitialized) {
        const sensorRepository = dataSourceInstance.getRepository('sensor')
        let body = {
            id: 11,
            name: 'test',
            address: 'test',
            status: true
        }
        let saveResult = await sensorRepository.save(body)
        console.log(saveResult)
        dataSourceInstance.destroy()
    }
}
run();

说明

node-oracledb typeorm 的集成还是比较方便的,没有什么问题

参考资料

https://github.com/oracle/node-oracledb
http://typeorm.io/#/

posted on   荣锋亮  阅读(29)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2022-10-14 docker desktop url protocl 技术以及使用
2020-10-14 apache ignite docker集群运行试用
2020-10-14 rr一款强大的应用请求录制以及回放框架
2020-10-14 追踪postgres 后端调用情况
2020-10-14 重置idea 配置的方法
2020-10-14 jdbc连接池工具与pg fdw连接的问题
2019-10-14 ent 基本使用八 索引

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示