使用Slick的代码生成器时,如何过滤掉列?

时间:2016-03-23 16:34:54

标签: scala slick

我使用Slick codegen工具并过滤掉表格并成功重命名表格和列。但是,如何跳过为不需要的列生成代码?

例如,在使用unwanted时,如何排除items表格中的SourceCodeGenerator列?

2 个答案:

答案 0 :(得分:3)

您可以按以下方式排除列:

  1. 覆盖工厂方法 private void BrdTracking_OnHolding(object sender, HoldingRoutedEventArgs e) { tbTracking.PreventKeyboardDisplayOnProgrammaticFocus = false; tbTracking.Focus(FocusState.Programmatic); tbTracking.PreventKeyboardDisplayOnProgrammaticFocus = true; }
  2. 从模型中排除列。
  3. 从新模型创建表。
  4. E.g:

    Table

答案 1 :(得分:0)

在Slick 3.3.0中,我必须覆盖已启用的列标志,并停止为索引和外键生成代码以使其工作:

val optDesiredColumns = Map(
    "table_1" -> Set("col_1", "col_2"),
    "table_2" -> Set("col_2", "col_3")
) 

val codegenFuture =  modelFuture.map { m =>
    val model = m
    new SourceCodeGenerator(model = model) {
    override def Table = tableModel => {
        val optDesiredColumns = tableNameToDesiredColumns.get(tableModel.name.table)
        new TableDef(tableModel) {
            override def Column = columnModel => {
                new ColumnDef(columnModel) {
                    override def enabled: Boolean = {
                        val rv = optDesiredColumns.map(desiredColumns =>
                            desiredColumns.contains(columnModel.name)).
                                getOrElse(super.enabled)
                        println(s"***** ${tableModel.name.table}.${columnModel.name} enabled = $rv")
                        rv
                    }
                }
            }

            override def Index = indexModel => {
                new IndexDef(indexModel)  {
                    override def enabled: Boolean = false
                }
            }

            override def ForeignKey = fkModel => {
                new ForeignKeyDef(fkModel)  {
                    override def enabled: Boolean = false
                }
            }
        }
    }
}