In RethinkDB, what is the easiest way to check if a database or a table exists?

前端 未结 3 466
庸人自扰
庸人自扰 2021-02-05 05:04

One way I know I can do it is by listing throughdbList() and tableList() and then looking for what I want in the results.

Is there an easier wa

3条回答
  •  时光说笑
    2021-02-05 05:32

    In JavaScript, given an array of table names, the shortest way is

    const tables = ['table1Name', 'table2Name', ...]
    const db = 'myDb'
    
    r(tables)
        .difference(r.db(db).tableList())
        .forEach(table => r.db(db).tableCreate(table))
        .run(connection)
    

提交回复
热议问题