use of com.nvlad.yii2support.database.TableInfo in project yii2support by nvlad.
the class DatabaseUtils method getColumnsByTable.
public static ArrayList<String> getColumnsByTable(String table, Project project) {
String prefixedTable = AddTablePrefix(table, true, project);
DbPsiFacade facade = DbPsiFacade.getInstance(project);
List<DbDataSource> dataSources = facade.getDataSources();
ArrayList<String> list = new ArrayList<>();
if (table == null)
return list;
table = ClassUtils.removeQuotes(prefixedTable);
for (DbDataSource source : dataSources) {
for (Object item : source.getModel().traverser().filter(DasTable.class)) {
if (item instanceof DasTable && ((DasTable) item).getName().equals(prefixedTable)) {
TableInfo tableInfo = new TableInfo((DasTable) item);
for (DasColumn column : tableInfo.getColumns()) {
list.add(ClassUtils.removeQuotes(column.getName()));
}
}
}
}
return list;
}
use of com.nvlad.yii2support.database.TableInfo in project yii2support by nvlad.
the class DatabaseUtils method getNotDeclaredColumns.
public static ArrayList<VirtualProperty> getNotDeclaredColumns(String table, Collection<Field> fields, Project project) {
DbPsiFacade facade = DbPsiFacade.getInstance(project);
List<DbDataSource> dataSources = facade.getDataSources();
final ArrayList<VirtualProperty> result = new ArrayList<>();
if (table == null)
return result;
for (DbDataSource source : dataSources) {
for (Object item : source.getModel().traverser().filter(DasTable.class)) {
table = ClassUtils.removeQuotes(table);
if (item instanceof DasTable && ((DasTable) item).getName().equals(table)) {
TableInfo tableInfo = new TableInfo((DasTable) item);
for (DasColumn column : tableInfo.getColumns()) {
boolean found = false;
PhpDocProperty prevProperty = null;
for (Field field : fields) {
if (field != null && field.getName().equals(column.getName())) {
found = true;
break;
}
}
if (!found) {
VirtualProperty newItem = new VirtualProperty(column.getName(), column.getDataType().typeName, column.getDataType().toString(), column.getComment(), null);
result.add(newItem);
}
}
}
}
}
return result;
}
use of com.nvlad.yii2support.database.TableInfo in project yii2support by nvlad.
the class DatabaseUtils method getLookupItemsByTable.
@Nullable
public static ArrayList<LookupElementBuilder> getLookupItemsByTable(String table, Project project, PhpExpression position) {
ArrayList<LookupElementBuilder> list = new ArrayList<>();
if (table == null || table.isEmpty())
return list;
DbPsiFacade facade = DbPsiFacade.getInstance(project);
List<DbDataSource> dataSources = facade.getDataSources();
// Code to test tests :)
// dataSources.clear();
// dataSources.add(new TestDataSource(project));
String prefixedTable = AddTablePrefix(table, true, project);
for (DbDataSource source : dataSources) {
for (Object item : source.getModel().traverser().filter(DasTable.class)) {
if (item instanceof DasTable && (((DasTable) item).getName().equals(prefixedTable) || ((DasTable) item).getName().equals(table))) {
TableInfo tableInfo = new TableInfo((DasTable) item);
for (DasColumn column : tableInfo.getColumns()) {
list.add(DatabaseUtils.buildLookup(column, true, project));
}
}
}
}
return list;
}
Aggregations