Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sequelize/sequelize-auto可以通过-t 表名指定某一张表,这个要怎么指定 #37

Open
TRIS-H opened this issue Aug 20, 2020 · 4 comments

Comments

@TRIS-H
Copy link

TRIS-H commented Aug 20, 2020

No description provided.

@TRIS-H TRIS-H closed this as completed Aug 20, 2020
@TRIS-H TRIS-H reopened this Aug 20, 2020
@nodejh
Copy link
Owner

nodejh commented Aug 20, 2020

  1. 可以用 --match, -m ,值是一个正则表达式
  2. 也可以在配置文件中,使用 tables/skipTables/match 来设置

@TRIS-H
Copy link
Author

TRIS-H commented Aug 20, 2020

假设我的表名为my_table_a, 我这样输入:
sequelize-automate -h ${sql.host} -d ${sql.database} -u ${sql.username} -p ${sql.password} -P ${sql.port} -m /my_table_a/
还是生成了全部,是哪里的问题?

@TRIS-H
Copy link
Author

TRIS-H commented Aug 20, 2020

瞄了下源码:
const dbOptions = _.assign({}, {
database: argv.d,
username: argv.u,
password: argv.p,
dialect: argv.e,
host: argv.h || '127.0.0.1',
port: argv.P || getDefaultPort(argv.e),
}, configFile ? configFile.dbOptions : {});

const options = _.assign({}, {
type: argv.t || 'js',
camelCase: !!argv.C,
dir: argv.o || path.resolve(${process.cwd()}/models),
emptyDir: !!argv.r,
}, configFile ? configFile.options : {});

貌似-m并无传递

@nodejh
Copy link
Owner

nodejh commented Aug 21, 2020

确实没有,我周末解决一下。试试用配置文件的方式?

// sequelize-automate.config.js
module.exports = {
  dbOptions: {
    database: "test",
    username: "root",
    password: "root",
    dialect: "mysql",
    host: "localhost",
    port: 3306,
    logging: false
  },
  options: {
    type: "js",
    dir: "models",
    tables: ["my_table_a"] // 只生成 my_table_a 的 model
 }
}
$ sequelize-automate -c "./sequelize-automate.config.js"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants