Press enter or click to view image in full size
#ShannonBase hashtag#MySQL Now, you can write Javascript Stored function and execute SQL statement in it with ShannonBase. With this feature and ML abilities, such as ML_generate, ML_RAG, ML_embeded_row, etc, ShannonBase has, We can develop a native agent engine in Javascript. That makes ShannonBase to be a AI-native data processing platform.
Taking the exmample below:
1: Create a table with sql statement:`
CREATE TABLE js_sp_test (
id INT AUTO_INCREMENT PRIMARY KEY,
segment VARCHAR(255) NOT NULL,
text VARCHAR(255) NOT NULL,
document_name VARCHAR(100) DEFAULT NULL,
segment_number INT DEFAULT 1,
metadata JSON DEFAULT (JSON_OBJECT())
) ENGINE=InnoDB;2: Insert some data into table.
INSERT INTO js_sp_test (segment, text, document_name, segment_number, metadata)
VALUES
(‘What is AutoML?’, (‘AutoML explanation example text’), ‘doc1’, 1, JSON_OBJECT(‘category’, ‘AI’)),
(‘AutoML automates model building’, (‘AutoML automates model building’), ‘doc1’, 2, JSON_OBJECT(‘category’, ‘AI’)),
(‘Machine learning basics’, (‘Basics of machine learning’), ‘doc2’, 1, JSON_OBJECT(‘category’, ‘ML’)),
(‘ShannonBase is an AI-native SQL engine’, (‘ShannonBase overview’), ‘doc3’, 1, JSON_OBJECT(‘category’, ‘DB’));3: Create the test stored function in javascript language.
DELIMITER |;
CREATE FUNCTION SELECT_DATA () RETURNS TEXT
LANGUAGE JAVASCRIPT AS $$
function select_data() {
return sys.exec_sql("SELECT id + 0 AS id, segment, text, document_name, segment_number, metadata FROM js_sp_test");
}
return select_data();
$$|
DELIMITER ;|4: Run the stored function.
SELECT SELECT_DATA();
Press enter or click to view image in full size
⭐ [Star the repo](https://github.com/Shannon-Data/ShannonBase)
🧩 [Submit PRs](https://github.com/Shannon-Data/ShannonBase/pulls)
🐞 [Open Issues](https://github.com/Shannon-Data/ShannonBase/issues)
💬 [Join Discussion](https://github.com/Shannon-Data/ShannonBase/discussions)