MySQL APIs
Execute queries against a MySQL database
While each Modus SDK offers similar capabilities, the APIs and usage may vary between languages.
Modus MySQL APIs documentation is available on the following pages:
- AssemblyScript MySQL APIs
- Go MySQL APIs (this page)
The Modus MySQL APIs allow you to run queries against MySQL or any MySQL-compatible database platform.
Import
To begin, import the mysql
package from the SDK:
MySQL APIs
The APIs in the mysql
package are below, organized by category.
We’re constantly introducing new APIs through ongoing development with early users. Please open an issue if you have ideas on what would make Modus even more powerful for your next app!
Functions
Execute
Execute a SQL statement against a MySQL database, without any data returned. Use this for insert, update, or delete operations, or for other SQL statements that don’t return data.
The Execute
function is for operations that don’t return data. However, some
insert/update/delete operations may still return data. In these cases, you can
use the QueryScalar
or Query
functions instead.
Name of the connection, as defined in the manifest.
SQL statement containing the query or mutation operation to execute.
While it’s possible to directly include parameter values into your SQL statement, it’s highly recommended to pass parameters as arguments instead. This can help to protect injection attacks and other security vulnerabilities.
Optional parameters to include with the query.
Query
Execute a SQL statement against a MySQL database, returning a set of rows. In
the results, each row converts to an object of type T
, with fields matching
the column names.
Type of object to use for the data returned from the query. This can be any type, including a custom type defined in your project. It should match the shape of the row returned from the SQL query.
Name of the connection, as defined in the manifest.
SQL statement containing the query or mutation operation to execute.
While it’s possible to directly include parameter values into your SQL statement, it’s highly recommended to pass parameters as arguments instead. This can help to protect injection attacks and other security vulnerabilities.
Optional parameters to include with the query.
QueryScalar
Execute a SQL statement against a MySQL database, returning a single scalar value. For example, the result could be a count, sum, or average, or it could be an identifier.
Type of object to use for the data returned from the query. This should generally be a scalar data type, such as a number or string. It should match the type of the data returned from the SQL query.
Name of the connection, as defined in the manifest.
SQL statement containing the query or mutation operation to execute.
While it’s possible to directly include parameter values into your SQL statement, it’s highly recommended to pass parameters as arguments instead. This can help to protect injection attacks and other security vulnerabilities.
Optional parameters to include with the query.
Types
Location
Represents a location on Earth, having Longitude
and Latitude
coordinates.
Correctly serializes to and from MySQL’s point type, in (longitude, latitude) order.
This struct is identical to the Point struct, but uses different field names.
The longitude coordinate of the location, in degrees.
The latitude coordinate of the location, in degrees.
Point
Represents a point in 2D space, having X
and Y
coordinates. Correctly
serializes to and from MySQL’s point type, in (x, y) order.
This struct is identical to the Location struct, but uses different field names.
The X coordinate of the point.
The Y coordinate of the point.
QueryResponse
Represents the response from a Query
operation.
The number of rows affected by the operation, which typically corresponds to the number of rows returned.
When inserting a row, this field contains the ID of the last inserted row. This is useful for tables with auto-incrementing primary keys.
An slice of objects, each representing a row returned from the query. Each object has fields corresponding to the columns in the result set.
Response
Represents the response from an Execute
operation.
The number of rows affected by the operation, which typically corresponds to the number of rows returned.
When inserting a row, this field contains the ID of the last inserted row. This is useful for tables with auto-incrementing primary keys.
ScalarResponse
Represents the response from a QueryScalar
operation.
The number of rows affected by the operation, which typically corresponds to the number of rows returned.
When inserting a row, this field contains the ID of the last inserted row. This is useful for tables with auto-incrementing primary keys.
The scalar value returned from the query.
Was this page helpful?