Skip to content

Latest commit

ย 

History

History
112 lines (83 loc) ยท 4.12 KB

File metadata and controls

112 lines (83 loc) ยท 4.12 KB

<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 ๋ฌธ๋ฒ•์„ ๋”ฐ๋ฅด๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.

์„ค์น˜๋ถ€ํ„ฐ ์–ด๋–ค ๋ฐฉ์‹์œผ๋กœ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ์ง€ ์•Œ์•„๋ณด๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

1. ์„ค์น˜

npm installation

yarn add alasql         # yarn
npm install alasql	# npm
npm install โ€“g alasql	# global installation for command line tools

CDN ์ด์šฉ

<script src="https://cdn.jsdelivr.net/npm/alasql@0.6"></script>

Local Library ์ €์žฅ ์‚ฌ์šฉ

https://github.com/agershun/alasql/tree/develop/dist

๊ฒฝ๋กœ : alasql/dist/alasql.js

2. ๋ฐ์ดํ„ฐ ์„ธํŒ… ๋ฐ ์‚ฌ์šฉ

1) SQL Table

/* 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");

2) Array Object

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]);

3) Spreadsheet

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);
        });

4) Bulk Data Load

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");

5) Precompile Statements

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])

3. Custom Function

/* 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โ€™)โ€™);

4. ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” Function

Custom ํ•จ์ˆ˜๊ฐ€ ์•„๋‹ˆ๋”๋ผ๋„ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ œ๊ณตํ•˜๋Š” ํ•จ์ˆ˜๋“ค์ด ์žˆ์Šต๋‹ˆ๋‹ค.

git clone https://github.com/agershun/alasql.wiki.git

๊ธฐ๋ณธ์ ์ธ sql ๋ฌธ๋ฒ•์„ ์ œ๊ณตํ•˜์ง€๋งŒ Wiki ๋ฅผ ํ†ตํ•ด์„œ ํ•œ๋ฒˆ ๋” ์ œ๊ณต๋˜๋Š” ๊ธฐ๋Šฅ์ธ์ง€ ํ™•์ธ ํ•˜์‹  ํ›„ ์‚ฌ์šฉํ•˜์‹œ๊ธฐ๋ฅผ ์ถ”์ฒœ ๋“œ๋ฆฝ๋‹ˆ๋‹ค.