API
HarmonySQL has a developer API for executing queries inside of databases.
In order to use the API you need to enable API access in the HarmonySQL config.
Code (YAML):
api_access
: true
If you want to create an instance of the API when your plugin loads, make sure to set HarmonySQL as a dependency.
Code (YAML):
depend
:
[HarmonySQL
]
The API will connect you to the same MySQL server as the credentials in the HamonySQL config.
Example:
Code (Java):
public
void onEnable
(
)
{
HarmonyAPI api
=
new HarmonyAPI
(Bukkit.
getServer
(
).
getPluginManager
(
).
getPlugin
(
"HarmonySQL"
)
)
;
try
{
api.
setDatabase
(
"DATABASE"
)
;
}
catch
(HarmonySQLException e
)
{
e.
printStackTrace
(
)
;
//gets thrown if api access is disabled
}
JSONArray rows
= api.
executeQuery
(
"SHOW TABLES"
)
;
for
(
int i
=
0
;i
<rows.
size
(
)
;i
++
)
{
JSONObject row
=
(JSONObject
) rows.
get
(i
)
;
row.
get
(
"COLUMN"
)
;
}
api.
executeSetQuery
(
"CREATE TABLE..."
)
;
//executes query that doesn't return anything
}