【问题标题】:how to convert snake casing to camel casing in adonis lucid database field如何在 adonis lucid 数据库字段中将蛇壳转换为骆驼壳
【发布时间】:2021-08-13 08:21:31
【问题描述】:

我已经在驼色外壳中创建了迁移,但是当我运行迁移时,它会自动将其转换为蛇形外壳。我怎样才能让它默认为驼峰式。

 public async up() {
    this.schema.createTable(this.tableName, (table) => {
      table.increments('id')
      table.string('firstName', 50).notNullable()
      table.string('lastName', 50).notNullable()
      table.string('email', 255).notNullable().unique()
      table.string('password', 180).notNullable()
      table.string('rememberMeToken').nullable()
      table.timestamp('createdAt', { useTz: true })
      table.timestamp('updatedAt', { useTz: true })
    })
  }

但是在数据库中它是这样显示的

【问题讨论】:

    标签: postgresql adonis.js lucid adonisjs-ace


    【解决方案1】:

    您可能希望将此添加到您的数据库配置中

    
    const { knexSnakeCaseMappers } = require("objection");
    
    pg: ({
        ...{
          client: 'pg',
          connection: {
            host: Env.get('HOST', '127.0.0.1'),
            port: Env.get('DB_PORT', ''),
            user: Env.get('DB_USER', 'user'),
            password: Env.get('DB_PASSWORD', ''),
            database: Env.get('DB_DATABASE', 'your_db_name')
          },
          debug: Env.get('DB_DEBUG', false)
        },
        ...knexSnakeCaseMappers() // This here should do the trick
      })
    

    问候。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-10-30
      • 2020-05-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-30
      相关资源
      最近更新 更多