Search in sources :

Example 6 with AstSelect

use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.

the class AstTest method selectWhereEmpty.

@Test
public void selectWhereEmpty() {
    Map<String, ? super Object> name = new HashMap<>();
    AstSelect users = Ast.selectCount().from("users").where(name);
    assertEquals("SELECT COUNT(*) AS \"count\" FROM users", users.format());
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 7 with AstSelect

use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.

the class AstTest method selectWhere2.

@Test
public void selectWhere2() {
    Map<String, ? super Object> names = new HashMap<>();
    names.put("name", "test");
    names.put("name2", "test2");
    AstSelect users = Ast.selectCount().from("users").where(names);
    assertEquals("SELECT COUNT(*) AS \"count\" FROM users WHERE name =? AND name2 =?", users.format());
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 8 with AstSelect

use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.

the class AstTest method selectWhereNotNull.

/**
 * todo можно сделать какой-нибудь хак (ID IS NULL OR ( null = ? ) )
 */
@Test
@Ignore
public void selectWhereNotNull() {
    Map<String, ? super Object> names = new HashMap<>();
    names.put("name", "null");
    AstSelect users = Ast.selectCount().from("users").where(names);
    assertEquals("SELECT COUNT(*) AS \"count\" FROM users WHERE name IS NULL", users.format());
    names.clear();
    names.put("name", "notNull");
    AstSelect users2 = Ast.selectCount().from("users").where(names);
    assertEquals("SELECT COUNT(*) AS \"count\" FROM users WHERE name IS NOT NULL", users2.format());
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) HashMap(java.util.HashMap) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 9 with AstSelect

use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.

the class AstTest method selectAll.

@Test
public void selectAll() {
    AstSelect users = Ast.selectAll().from("users");
    assertEquals("SELECT * FROM users", users.format());
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) Test(org.junit.Test)

Example 10 with AstSelect

use of com.developmentontheedge.sql.model.AstSelect in project be5 by DevelopmentOnTheEdge.

the class ProvincesRepository method findAll.

@Override
public Iterable<Provinces> findAll(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = Provinces.class) Closure conditions) {
    Map<String, Object> conditionsMap = toMap(conditions);
    AstSelect sql = Ast.selectAll().from(entityName).where(conditionsMap);
    return db.query(sql.format(), beanListHandler, conditionsMap.values().toArray());
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect)

Aggregations

AstSelect (com.developmentontheedge.sql.model.AstSelect)28 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)11 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)10 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)9 AstFrom (com.developmentontheedge.sql.model.AstFrom)8 AstQuery (com.developmentontheedge.sql.model.AstQuery)8 Test (org.junit.Test)8 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)7 AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)6 AstLimit (com.developmentontheedge.sql.model.AstLimit)6 AstWhere (com.developmentontheedge.sql.model.AstWhere)5 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)5 HashMap (java.util.HashMap)5 AstFunNode (com.developmentontheedge.sql.model.AstFunNode)4 AstFieldReference (com.developmentontheedge.sql.model.AstFieldReference)3 AstOrderBy (com.developmentontheedge.sql.model.AstOrderBy)3 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)3 DynamicProperty (com.developmentontheedge.beans.DynamicProperty)2 DynamicPropertySet (com.developmentontheedge.beans.DynamicPropertySet)2 DynamicPropertySetSupport (com.developmentontheedge.beans.DynamicPropertySetSupport)2