Nesse artigo veremos como executar consultas nativas através da API do Veloster Framework.
Uso
As consultas nativas estão disponíveis na interface de serviços Veloster<T>, através dos métodos:
Java Code
// query type update | delete | insert
void executeNativeQuery(String query, Object... params);
// query type select
List<Object[]> executeNativeSelect(String query, Object... args);
void executeNativeQuery(String query, Object... params);
// query type select
List<Object[]> executeNativeSelect(String query, Object... args);
As consultas seguem o padrão JDBC de argumentos.
Exemplo:
Java Code
Veloster<Person> veloster = VelosterRepository.getORM(Person.class);
veloster.executeNativeQuery("delete from person where id = ?", 1)
// or
List<Object[]> items = veloster.executeNativeSelect("select id, name from person");
for(Object[] vet : items){
say("person: id[" + ver[0] + "] name[" + vet[1] + "]");
}
veloster.executeNativeQuery("delete from person where id = ?", 1)
// or
List<Object[]> items = veloster.executeNativeSelect("select id, name from person");
for(Object[] vet : items){
say("person: id[" + ver[0] + "] name[" + vet[1] + "]");
}