简体   繁体   English

FeathersJS API + Firebase 实时数据库

[英]FeathersJS API + Firebase Realtime Database

I would like to if there is way to use a Firebase Realtime Database with Sequelize on a FeathersJS API.我想知道是否有办法在 FeathersJS API 上使用带有 Sequelize 的 Firebase 实时数据库。

My API is setup with a local mariadb this way, in the sequelize.js:我的 API 在 sequelize.js 中以这种方式使用本地 mariadb 设置:

const Sequelize = require('sequelize');

module.exports = function (app) {
  const sequelize = new Sequelize(
    'dbName',
    'username',
    'password',
     {
       host: 'mariadb',
       dialect: 'mysql'
     }
   );
  const oldSetup = app.setup;

  app.set('sequelizeClient', sequelize);

  app.setup = function (...args) {
    const result = oldSetup.apply(this, args);

    // Set up data relationships
    const models = sequelize.models;
    Object.keys(models).forEach(name => {
      if ('associate' in models[name]) {
        models[name].associate(models);
      }
    });

    // Sync to the database
    app.set('sequelizeSync', sequelize.sync());

    return result;
  };
};

I need everything here especially relationships.我需要这里的一切,尤其是人际关系。

So I am able to use realtime db/firestore db with feathersJS sequelize?所以我可以将实时数据库/firestore 数据库与 feathersJS sequelize 一起使用吗?

/node_modules/feathers-sequelize/lib/index.js:31
2022-12-08 12:15:50       Sequelize = options.Model.sequelize.Sequelize;
2022-12-08 12:15:50                                           ^
2022-12-08 12:15:50 
2022-12-08 12:15:50 TypeError: Cannot read properties of undefined (reading 'Sequelize')

The only thing I have from realtime database is databaseURL, or maybe should I use the SDK?我唯一从实时数据库中获得的是 databaseURL,或者我应该使用 SDK?

Maybe try edit your code to this:也许尝试将您的代码编辑为:

// const Sequelize = require('sequelize');  //remove this
const sequelize = require("firestore-sequelize"); //replace with this
const admin = require("firebase-admin");

module.exports = function (app) {
  //   const sequelize = new Sequelize(
  //     'dbName',
  //     'username',
  //     'password',
  //      {
  //        host: 'mariadb',
  //        dialect: 'mysql'
  //      }
  //    );

  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  });
  
  sequelize.initializeApp(admin)
  
  const oldSetup = app.setup;

  app.set("sequelizeClient", sequelize);

  app.setup = function (...args) {
    const result = oldSetup.apply(this, args);

    // Set up data relationships
    const models = sequelize.models;
    Object.keys(models).forEach((name) => {
      if ("associate" in models[name]) {
        models[name].associate(models);
      }
    });

    // Sync to the database
    app.set("sequelizeSync", sequelize.sync());

    return result;
  };
};

As for the authentication/credentials read this first since google has to recognize you and permitted access.至于身份验证/凭证,请先阅读此内容,因为谷歌必须识别您并允许访问。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM