gausszhou / sqlike

使用 JavaScript 模拟 SQL 的部分功能

Home Page:https://gausszhou.github.io/sqlike

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sqlike

example

// Example usage
type User = { id: number; name: string; age: number, city: string };

const users:User[] = [
  { id: 1, name: 'Alice', age: 20 ,city: 'New York'},
  { id: 2, name: 'Bob', age: 25 ,city: 'New York'},
  { id: 3, name: 'Charlie', age: 30, city: 'Los Angeles' },
  { id: 4, name: 'David', age: 25 ,city: 'Los Angeles'},
  { id: 5, name: 'Ethan', age: 30 ,city: 'New York'},
  { id: 6, name: 'Frank', age: 20 ,city: 'New York'},
];

groupBy

// groupBy(list, groupKey)
const groupedUsers1 = groupBy(users, 'age');
const groupedUsers2 = groupByMultiple(users, ['age', 'city']);

sortBy

// sortBy(list, comparator)
const sortedUsers1 = sortBy(users, (a, b) => a.age - b.age);
const sortedUsers2 = sortByMultiple(users, [
  (a, b) => a.city.localeCompare(b.city), // First sort by city
  (a, b) => a.age - b.age// Then sort by age if city is the same
]);

limit

// limit(list, limit, offset)
const limitedUsers = limit(users, 3);
const limitedUsers = limit(users, 3, 1);

About

使用 JavaScript 模拟 SQL 的部分功能

https://gausszhou.github.io/sqlike


Languages

Language:TypeScript 70.8%Language:CSS 20.9%Language:HTML 5.8%Language:Shell 1.8%Language:JavaScript 0.7%