-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
42 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
demo/src/test/java/cc/carm/lib/easysql/tests/TableMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package cc.carm.lib.easysql.tests; | ||
|
||
import cc.carm.lib.easysql.TestHandler; | ||
import cc.carm.lib.easysql.api.SQLManager; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Set; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
public class TableMetadataTest extends TestHandler { | ||
|
||
@Override | ||
public void onTest(SQLManager sqlManager) throws Exception { | ||
|
||
print(" 获取数据库中所有的表"); | ||
CompletableFuture<List<String>> tables = sqlManager.fetchMetadata( | ||
(meta) -> meta.getTables(null, null, "%", new String[]{"TABLE"}), | ||
(rs) -> { | ||
List<String> data = new ArrayList<>(); | ||
while (rs.next()) { | ||
data.add(rs.getString("TABLE_NAME")); | ||
} | ||
return data; | ||
} | ||
); | ||
print("表名:" + Arrays.toString(tables.get().toArray())); | ||
|
||
print(" 获取数据库中所有的列"); | ||
CompletableFuture<Set<String>> columns = sqlManager.fetchTableMetadata("test%").listColumns(); | ||
print("列名:" + Arrays.toString(columns.get().toArray())); | ||
|
||
print("表是否存在 " + sqlManager.fetchTableMetadata("test_user_info").validateExist().get()); | ||
print("列是否存在 " + sqlManager.fetchTableMetadata("test_user_info").isColumnExists("uid").get()); | ||
|
||
} | ||
|
||
} |