Git Product home page Git Product logo

sqlbuilder's Introduction

SqlBuilder

  • use case:

    • When nosql adapt to sql api by and by, we have to convert nosql to sql.
  • You can use this SqlSrcipt.Builer to make your sql easily.

  • examples:

public class PersonSqlBuilderTest {
    private static final Logger log = LoggerFactory.getLogger(PersonSqlBuilderTest.class);

    @Test
    public void testBuildSql() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        SqlBuilderUtils.setTableNameMap(Person.class,SqlBuilderUtils.getTableNameInitial(Person.class));
        //建造者模式 Builder
        SqlScript.Builder<Person> builder = new SqlScript.Builder<Person>(new Person());
        SqlScript script = builder
                .select(Person::getName, Person::getAddress)
                .from(SqlBuilderUtils.getTableName(Person.class))
                .where("1=1")
                .groupBy(builder.getColumnStr(Person::getName))
                .build();
        String sqlStr = script.getSqlStr();
        log.info(sqlStr);
    }

    @Test
    public void testParseContent() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException {
        SqlBuilderUtils.setTableNameMap(Person.class,SqlBuilderUtils.getTableNameInitial(Person.class));
        //some examples for olap query result
        //we can user this to convert nosql to sql (this example string from kylin api results)
        String content = "{\"columnMetas\":[{\"isNullable\":1,\"displaySize\":256,\"label\":\"ID\",\"name\":\"ID\",\"schemaName\":\"DEFAULT\",\"catelogName\":null,\"tableName\":\"TEST_PERSON\",\"precision\":256,\"scale\":0,\"columnType\":4,\"columnTypeName\":\"VARCHAR\",\"signed\":true,\"autoIncrement\":false,\"caseSensitive\":true,\"searchable\":false,\"currency\":false,\"definitelyWritable\":false,\"writable\":false,\"readOnly\":true},{\"isNullable\":1,\"displaySize\":256,\"label\":\"NAME\",\"name\":\"NAME\",\"schemaName\":\"DEFAULT\",\"catelogName\":null,\"tableName\":\"TEST_PERSON\",\"precision\":256,\"scale\":0,\"columnType\":4,\"columnTypeName\":\"VARCHAR\",\"signed\":true,\"autoIncrement\":false,\"caseSensitive\":true,\"searchable\":false,\"currency\":false,\"definitelyWritable\":false,\"writable\":false,\"readOnly\":true},{\"isNullable\":1,\"displaySize\":256,\"label\":\"SEX\",\"name\":\"SEX\",\"schemaName\":\"DEFAULT\",\"catelogName\":null,\"tableName\":\"TEST_PERSON\",\"precision\":256,\"scale\":0,\"columnType\":4,\"columnTypeName\":\"INTEGER\",\"signed\":true,\"autoIncrement\":false,\"caseSensitive\":true,\"searchable\":false,\"currency\":false,\"definitelyWritable\":false,\"writable\":false,\"readOnly\":true},{\"isNullable\":1,\"displaySize\":256,\"label\":\"ADDRESS\",\"name\":\"ADDRESS\",\"schemaName\":\"DEFAULT\",\"catelogName\":null,\"tableName\":\"TEST_PERSON\",\"precision\":256,\"scale\":0,\"columnType\":4,\"columnTypeName\":\"VARCHAR\",\"signed\":true,\"autoIncrement\":false,\"caseSensitive\":true,\"searchable\":false,\"currency\":false,\"definitelyWritable\":false,\"writable\":false,\"readOnly\":true}],\"results\":[[8,\"lily\",0,\"淮安市\"]],\"cube\":\"CUBE[name=person_cube]\",\"affectedRowCount\":0,\"isException\":false,\"exceptionMessage\":null,\"duration\":51,\"totalScanCount\":2,\"totalScanBytes\":100,\"hitExceptionCache\":false,\"storageCacheUsed\":false,\"traceUrl\":null,\"pushDown\":false,\"partial\":false}";
        ResultEntity resultEntity = JSON.parseObject(content, ResultEntity.class);
        OlapResultEntityHandler<Person> entityHandler = new OlapResultEntityHandler<>();
        entityHandler.handleCollectionResult(Person.class,resultEntity.getColumnMetas(),resultEntity.getResults());
        List<Person> results = entityHandler.getResults();
        Assert.assertNotNull(results);

    }

}

sqlbuilder's People

Contributors

czyerchen avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.