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

SqlBuilder.InsertIntoNextStep does not support building #900

Open
qichangleixin opened this issue Jan 20, 2025 · 1 comment
Open

SqlBuilder.InsertIntoNextStep does not support building #900

qichangleixin opened this issue Jan 20, 2025 · 1 comment

Comments

@qichangleixin
Copy link

qichangleixin commented Jan 20, 2025

This is how I currently implement dynamic insertion
`

public static GeneralInsertStatementProvider buildInsert(FormDynamicInsert formDynamicInsert) {
        SqlTable sqlTable = SqlTable.of(formDynamicInsert.getTableName());
        SqlBuilder.InsertIntoNextStep insertIntoNextStep = SqlBuilder.insertInto(sqlTable);
        for(int i=0;i<formDynamicInsert.getFields().size()-2; i++) {
            FormDynamicInsert.InsertField insertField = formDynamicInsert.getFields().get(i);
            insertIntoNextStep.set(sqlTable.column(insertField.getField())).toValue(insertField.getValue());
        }
        FormDynamicInsert.InsertField lastInsertField = formDynamicInsert.getFields().get(formDynamicInsert.getFields().size()-1);
        return insertIntoNextStep.set(sqlTable.column(lastInsertField.getField())).toValue(lastInsertField.getValue())
                .build().render(RenderingStrategies.MYBATIS3);
    }

`
But I want to achieve it this way

Image
Is there a problem with my implementation method?

@jeffgbutler
Copy link
Member

jeffgbutler commented Jan 20, 2025

You can do it by directly using the GeneralInsertDSL.

public static GeneralInsertStatementProvider buildInsert(FormDynamicInsert formDynamicInsert) {
    SqlTable sqlTable = SqlTable.of(formDynamicInsert.getTableName());
    GeneralInsertDSL dsl = GeneralInsertDSL.insertInto(sqlTable);
    formDynamicInsert.getFields().forEach(f -> {
        dsl.set(f.getField()).toValue(f.getValue());
    });
    return dsl.build.render(RenderingStrategies.MYBATIS3);
}

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