While developing applications with Kuika, you can add Custom Actions that you create through SQL queries to improve the functions of your application and increase the functions in your application.
You can connect the Custom Actions you create in your application to the screens and add Custom Actions to the elements on the screens.
You can create special actions in an application you develop with Kuika and use the actions you create on screens.
1. Creating a Custom Action Using SQL Editor
To create a custom action, open the Datasources view mode.
Through the left menu in Datasources view mode, you can view the data sources, actions and tables in the application you have developed, add a new data source, a new action and a new table.
To add a new custom action, hover over the Actions sub-panel with the cursor. Click on the ‘+’ icon next to the Actions sub-panel.
You can create a New SQL Action or a New Folder via the drop-down menu. If you want to create a new Custom Actions under the Actions sub-panel, click New SQL Actions. If you want to create Custom Actions under a new file, click New Folder and create the file by naming it.
Let's create an action that allows listing the departments in a personnel list within the scope of a sample scenario. Before creating this action, you must create a table named Department. You can examine our related content in detail for table creation operations.
You are expected to list the departments in the application on the department listing screen. For this, create a custom action named SelectDepartmentList.
A SQL Editor will greet you on the screen that opens. Write the SQL query required for listing in the SQL Editor.
Kuika provides you some convenience in adding queries. This convenience creates automatic queries specific to tables on the query insertion screen.
To add automatic queries specific to the table, hover over the tables in the left menu on the query insertion screen. Click on the three dots next to the table. Kuika allows you to automatically add and modify Select, Update and Delete queries.
You can use the following query to list the departments with SelectDepartmentList special action.
Copyselect * from Department WHERE DepartmentName LIKE @searchFor OR @searchFor is null OR @searchFor = '' ORDER BY DepartmentName
After writing the query, you can test the query via the TEST button in the upper right corner and create the special action by clicking the CREATE button.
You can create custom actions to increase the functionality of your application. You can use Custom Actions panel in UI Design view mode and/or Actions section in Datasources view mode to create custom actions.
Let's examine how to create a custom action with the Custom Actions panel in UI Design view mode.
Open the Custom Actions panel and click the Add SQL Action button, the SQL Editor below will open on the next screen.
Let's take a closer look at the fields shown with numbers in the image above and examine the process of creating a custom action.
You can add and update the action name with SQL Actions name field. You can use English language alphabet characters and also ‘-’ or ‘_’ characters in naming.
You can expand the SQL editor, which opens modally in the UI Design view, as full screen or use it in its standard size.
You can create an action by entering the SQL query of the special action you want to create in the SQL editor field.
Kuika allows you to quickly add Select, Save and Delete queries that you will need during the action creation process.
For this process, hover over the tables on the left side with the cursor. By clicking on the three dots to the right of the table names, you can create and quickly add Select, Select By Id, Save, Delete, Search By Keyword and Search With Pagination queries for the selected table with one click.
Select is used to select records in database tables and return data that matches certain query criteria. For example,
“SELECT* FROM table_name”
such query is created.
Used to select a specific record using a unique ID from a database table. For example,
SELECT * FROM table_name WHERE id = certain_id;
creates a SQL query such as.
Add Save Query action is used to add a new record to the database and/or update an existing record. The Save action first queries whether there is a record in the table with the Update command and if there is a record, it updates the record with the new data. If there is no record, the Insert Into command is activated and creates a new record in the data table.
DELETE operation is used to delete a record in the database. For example
DELETE FROM table_name WHERE condition expression”
It is used to search for records in the database table according to a specific keyword. It returns records matching the keyword. For example,
SELECT * FROM table_name WHERE column_name LIKE ‘%key_keyword%’;
It is used to search for records in a database table by keyword and split the results into pages. Paging is done using LIMIT and OFFSET. For example,
SELECT * FROM table_name WHERE column_name LIKE ‘%key_keyword%’ LIMIT page_size OFFSET start;
While writing your SQL queries, you can quickly prepare actions by getting support from the artificial intelligence assistant. Open the chat area with Generate with AI from the top section. Select the data table that the query will use for the action via Selectbox. Then define the query you want to create using the table and enter it as Prompt. For example; Enter the prompt I need a query that allows items to be deleted.
A suitable query is prepared with artificial intelligence. You can use it by adding the query with copy/paste into SQL editor.
You can quickly add the queries created and copied with the artificial intelligence assistant to the SQL Editor via the button in the image above.
Through the parameter panel, you can view the parameters in your custom action for which you have manually written SQL queries or prepared queries with the AI assistant.
You can show/hide the panel with the on/off button in the upper right corner. This panel is dynamically updated according to the parameters of the action you have created.
You can test the result of the query you added with the SQL editor with the TEST button.
After completing all operations, you can complete the custom action creation process by clicking the CREATE button.
When defining an action, the Declare command is used for variable declarations in the SQL editor.
In general, this command allows you to specify the name, data type and, if necessary, the initial value of a variable.
General Declare format;
DECLARE @variable_name data_type;
Specifies that a variable named @variable_name is of type data_type. data_type is a SQL data type (nvarchar, int, bit, etc.)
Value assignment can be done in two ways.
Select @variable= deger from table_name
or
the ET command is used.
SET @variable = deger.
Example1:
DECLARE @top1Product nvarchar(256)SELECT top1 @top1Product = productName from table_name
Example2:
DECLARE @rowCount intSET @rowCount=(select count(Id) from table_name)
In these SQL code examples, two variables (@top1Product and @rowCount) are defined using the DECLARE statement and then values are assigned to these variables.
If you want to write the Declare function in the SQL Editor within the Kuika platform, you can manually enter the queries in the SQL Editor or you can get support from the Artificial Intelligence Assistant. For this, you can activate the Generate with AI switch, select the table of the Declare function you want to write and enter a prompt such as ‘write declare command in table_name table’ in the searchbox field. The artificial intelligence assistant will easily create the function for you.