2-Single User with UnStructured Data
2.1. Task
2.2. Example code to Insert cipher
import {MindLake} from 'mind-lake-sdk';
import md5 from 'js-md5';
const DataType = MindLake.DataType;
const response = await fetch("https://avatars.githubusercontent.com/u/97393721");
if(!response || response.status !== 200) {
return console.error("Failed to get picture from github")
}
const image = await response.arrayBuffer();
console.log("MD5 of the original picture pic_origin.png: ", md5(image));
const base64 = Buffer.from(image).toString('base64');
const mindLake = await MindLake.getInstance("YOU OWN APP KEY");
// connect to MindLake."5" is example of Goerli Testnet chainId
const chainId = "5"
const res1 = await mindLake.connect(chainId);
if(res1.code !== 0) {
console.error(res1.message);
return
}
// create a table
const dataLake = mindLake.dataLake;
await dataLake.dropTable("album");
const res2 = await dataLake.createTable("album", [{columnName: 'name', type: DataType.text, encrypt: false}, {columnName: 'picture', type: DataType.text, encrypt: true}]);
if(res2.code !==0) {
console.error(res2.message);
return
}
const cryptor = mindLake.cryptor;
const res3 = await cryptor.encrypt(base64, "album.picture");
if(res3.code !== 0) {
console.error(res3.message);
return
}
const sql = `insert into album (name, picture) values ("mind.png", '${res3.result}')`;
const res4 = await dataLake.query(sql);
if(res4.code !== 0) {
console.error(res4.message);
return
}2.3. Result Table in MindLake
name
picture
2.4. Example code to query on cipher
2.5. Output
Last updated