<AlaSQL!! ๋ฐ์์ รฆlรฆ ์จ๋ SQL? ์ด๋ผ๊ณ ํ๋ฉด ๋ ๊ฒ ๊ฐ์ต๋๋ค.
AlaSQL์ ๋ฌด์์ผ๊น์?
AlaSQL์ ๊ด๊ณํ ๋ฐ์ดํฐ์ Schemaless ๋ฐ์ดํฐ์ ์ฟผ๋ฆฌ ์๋ ๋ฐ ๋ฐ์ดํฐ ์์ค ์ ์ฐ์ฑ์ ์ค์ ์ ๋ javascript ์ฉ ์คํ์์ค SQL ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋๋ค.
AlaSQL์ ๋ํ ๋ด์ฉ์ ์๋ ์์ธํ ์ค๋ช ๋์ด ์์ต๋๋ค.
https://github.com/agershun/alasql
๋ผ์ด๋ธ๋ฌ๋ฆฌ ์ค๊ณ ๋ชฉ์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค
-
BI ๋ฐ ERP Application์ ์ํ ๋น ๋ฅธ ๋ฉ๋ชจ๋ฆฌ ๋ด SQL ๋ฐ์ดํฐ ์ฒ๋ฆฌ
-
๊ฐํธํ ETL
-
๋ชจ๋ ๋ธ๋ผ์ฐ์ , Node.js ๊ทธ๋ฆฌ๊ณ ๋ชจ๋ฐ์ผ ์ดํ๋ฆฌ์ผ์ด์ ์์์ ์ฌ์ฉ
์ฌ์ฉํ๋ฉด์ ๊ฐ์ฅ ํธํ๊ฒ ์ฌ์ฉํ๋ ๋ด์ฉ์ API๋ฅผ ํธ์ถ ํด์ ๋ฐํ ๋ฐ์ json ํ์์ ๋ฐ์ดํฐ ๋ฆฌ์คํธ๋ฅผ ์ํ๋ ์กฐ๊ฑด, ๊ฐ์ ๋ํด์ ๊ฒ์ํ ๋ ์ฌ์ฉํ๋ ์ฝ๊ณ ๋น ๋ฅด๊ฒ ์ํ๋ ๋ฐ์ดํฐ๋ฅผ ์ถ์ถํด ๋ผ ์ ์์์ต๋๋ค. Excel, CSV, JSON, TAB, IndexedDB, LocalStorage, SQLite ํ์์ ํ์ผ์ ์ฌ์ฉํ ์ ์์ต๋๋ค. ์ฌ์ฉ ๋ฐฉ๋ฒ์ ์ ํ์ ์ผ๋ก SQL ๋ฌธ๋ฒ์ ๋ฐ๋ฅด๊ณ ์์ต๋๋ค.
์ค์น๋ถํฐ ์ด๋ค ๋ฐฉ์์ผ๋ก ์ฌ์ฉ ๊ฐ๋ฅํ์ง ์์๋ณด๋๋ก ํ๊ฒ ์ต๋๋ค.
yarn add alasql # yarn
npm install alasql # npm
npm install โg alasql # global installation for command line tools
<script src="https://cdn.jsdelivr.net/npm/alasql@0.6"></script>
https://github.com/agershun/alasql/tree/develop/dist
๊ฒฝ๋ก : alasql/dist/alasql.js
/* create SQL Table and add data */
alasql("CREATE TABLE cities (city string, pop number)");
/* Insert Data*/
alasql("INSERT INTO cities VALUES ('Paris',2249975),('Berlin',3517424),('Madrid',3041579)");
/* execute query */
var res1 = alasql("SELECT * FROM cities WHERE pop < 3500000 ORDER BY pop DESC");
var data = [ {a: 1, b: 10}, {a: 2, b: 20}, {a: 1, b: 30} ];
var res2 = alasql('SELECT a, SUM(b) AS b FROM ? GROUP BY a',[data]);
alasql(['SELECT * FROM XLS("data/mydata") WHERE city = "London" '])
.then(function(res){
console.log(res);
}).catch(function(err){
console.log('Does the file exist? There was an error:', err);
});
alasql("CREATE TABLE example4 (a INT, b INT)");
// alasql's data store for a table can be assigned directly
alasql.tables.example4.data = [ {a:2,b:6}, {a:3,b:4} ];
// ... or manipulated with normal SQL
alasql("INSERT INTO example4 VALUES (1,5)");
var res = alasql("SELECT * FROM example4 ORDER BY b DESC");
var data = [{a:1},{a:2},{a:3},{a:4},{a:5}];
// Compile
var mysum = alasql.compile("SELECT VALUE SUM(a) FROM ? WHERE a > 2");
// Run
var res5 = mysum([data])
/* Query์์ datetime ํจ์๋ฅผ ์ฌ์ฉํ๊ธฐ ์ํด์ custom ํจ์ ์์ฑ */
alasql.fn.datetime = function (param) {
var origin_date = new Date((Date.parse(param)));
var start_date = origin_date.getDate();๏ฟฝstart_date = start_date >= 10 ? start_date : '0' + start_date;๏ฟฝvar origin_month = (1 + origin_date.getMonth())๏ฟฝorigin_month = origin_month >= 10 ? origin_month : '0' + origin_month;๏ฟฝvar origin_time = origin_date.getHours();๏ฟฝorigin_time = origin_time >= 10 ? origin_time : '0' + origin_time;๏ฟฝvar origin_minute = origin_date.getMinutes();๏ฟฝorigin_minute = origin_minute >= 10 ? origin_minute : '0' + origin_minute;๏ฟฝvar origin_second = origin_date.getSeconds();๏ฟฝorigin_second = origin_second >= 10 ? origin_second : '0' + origin_second;๏ฟฝresult = origin_date.getFullYear() + "-" + origin_month + "-" + start_date + " " + origin_time + ":" + origin_minute + ":" + origin_second;
}
var res = alasql('SELECT datetime(โ20200716โ)โ);
Custom ํจ์๊ฐ ์๋๋๋ผ๋ ๊ธฐ๋ณธ์ ์ผ๋ก ์ ๊ณตํ๋ ํจ์๋ค์ด ์์ต๋๋ค.
git clone https://github.com/agershun/alasql.wiki.git
๊ธฐ๋ณธ์ ์ธ sql ๋ฌธ๋ฒ์ ์ ๊ณตํ์ง๋ง Wiki ๋ฅผ ํตํด์ ํ๋ฒ ๋ ์ ๊ณต๋๋ ๊ธฐ๋ฅ์ธ์ง ํ์ธ ํ์ ํ ์ฌ์ฉํ์๊ธฐ๋ฅผ ์ถ์ฒ ๋๋ฆฝ๋๋ค.