{"id":13727084,"url":"https://github.com/sinclairzx81/linqbox","last_synced_at":"2025-04-14T09:42:24.162Z","repository":{"id":57160466,"uuid":"250390476","full_name":"sinclairzx81/linqbox","owner":"sinclairzx81","description":"Language Integrated Query for JavaScript","archived":false,"fork":false,"pushed_at":"2020-03-27T08:48:11.000Z","size":293,"stargazers_count":132,"open_issues_count":0,"forks_count":4,"subscribers_count":9,"default_branch":"master","last_synced_at":"2024-10-19T11:12:16.040Z","etag":null,"topics":["javascript","language-integrated-query","lazy-evaluation","linq","query-builder"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sinclairzx81.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-03-26T22:59:25.000Z","updated_at":"2024-10-03T04:33:05.000Z","dependencies_parsed_at":"2022-09-09T07:01:00.804Z","dependency_job_id":null,"html_url":"https://github.com/sinclairzx81/linqbox","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Flinqbox","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Flinqbox/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Flinqbox/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sinclairzx81%2Flinqbox/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sinclairzx81","download_url":"https://codeload.github.com/sinclairzx81/linqbox/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248855961,"owners_count":21172673,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","language-integrated-query","lazy-evaluation","linq","query-builder"],"created_at":"2024-08-03T01:03:38.827Z","updated_at":"2025-04-14T09:42:24.121Z","avatar_url":"https://github.com/sinclairzx81.png","language":"TypeScript","readme":"\u003cdiv align='center'\u003e\n\n\u003ch1\u003eLinqBox\u003c/h1\u003e\n\n\u003cp\u003eLanguage Integrated Query for JavaScript\u003c/p\u003e\n\n[![npm version](https://badge.fury.io/js/%40sinclair%2Flinqbox.svg)](https://badge.fury.io/js/%40sinclair%2Flinqbox)\n[![GitHub CI](https://github.com/sinclairzx81/linqbox/workflows/GitHub%20CI/badge.svg)](https://github.com/sinclairzx81/linqbox/actions)\n\n\n\u003cimg src=\"./doc/logo.png\"\u003e\u003c/img\u003e\n\n\u003c/div\u003e\n\n\n##### If it's possible in C#\n```csharp\nusing System.Linq;\n\nvar query = from n in new int [] { 0, 1, 2 } select n + 1;\n\nConsole.WriteLine(query.ToList());\n```\n##### Let it be so for JavaScript\n```typescript\nimport { linq } from '@sinclair/linqbox'\n\nconst query = linq `from n in [0, 1, 2] select n + 1`\n\nconsole.log([...query])\n```\n\n\u003ca name=\"Overview\"\u003e\u003c/a\u003e\n\n## Overview\n\nLinqBox is an experimental implementation of Language Integrated Query for JavaScript. It is written as an abstraction for JavaScript generators where it allows sequences of generators to be functionally composed through LINQ query expression syntax. \n\n LinqBox provides a sole [Tagged Template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals) function as its API. Within it, one can write a typical LINQ expression. LinqBox will parse it, build a syntax tree representation of it; and construct a series of `function*` generators to execute the query at a later point in time. The queryable object it returns is a `Enumerable\u003cT\u003e` which houses the parsed syntax tree and which implements a `[Symbol.iterator]`. The syntax tree itself can be reflected and potentially mapped to other domains such as SQL.\n\nLinqBox was written as a research project to explore leveraging LINQ as a form of unified query syntax for JavaScript. It does require an ES6+ JavaScript runtime, should work ok on most modern browsers.\n\nThis project is offered as is to anyone who may find it of use.\n\nLicense MIT\n\n## Contents\n\n- [Overview](#Overview)\n- [Install](#Install)\n- [Syntax](#Syntax)\n- [Keywords](#Keywords)\n\n\u003ca name=\"Install\"\u003e\u003c/a\u003e\n\n## Install\n```bash\n$ npm install @sinclair/linqbox\n```\n\n\u003ca name=\"Syntax\"\u003e\u003c/a\u003e\n\n## Syntax\n\nLinqbox implements a JavaScript version of LINQ as one would probably imagine it. Internally Linqbox parses for all JavaScript expressions (except functions) and constructs \u003ca href=\"https://github.com/estree/estree\"\u003eESTree\u003c/a\u003e based expressions trees that are extended to support the standard set of LINQ clauses and keywords. The following is a brief example of its usage. For more comprehensive information on LINQ, refer to the official Microsoft documentation located [here](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/linq/).\n\n### Example\n\n```typescript\nimport { linq } from '@sinclair/linqbox'\n\nconst users = [\n  { userid: 0, name: 'dave' },\n  { userid: 1, name: 'bob' },\n  { userid: 2, name: 'alice' },\n  { userid: 3, name: 'roger' },\n]\nconst records = [\n  { recordid: 0, userid: 0, data: 'toaster' },\n  { recordid: 1, userid: 2, data: 'fridge' },\n  { recordid: 2, userid: 1, data: 'television' },\n  { recordid: 3, userid: 4, data: 'toaster' },\n  { recordid: 4, userid: 2, data: 'stove' },\n  { recordid: 5, userid: 0, data: 'couch' },\n  { recordid: 6, userid: 2, data: 'computer' },\n  { recordid: 7, userid: 2, data: 'washing machine' },\n  { recordid: 8, userid: 3, data: 'remote control' },\n  { recordid: 9, userid: 1, data: 'air conditioner' },\n]\n\nconst query = linq`\n  from user in ${users}\n  join record in ${records}\n    on user.userid equals record.userid \n      into records\n  select {\n    user,\n    records\n  }`\n\nfor (const value of query) {\n  console.log(value)\n}\n```\nResults in the following output\n```javascript\n{\n    user: { userid: 0, name: 'dave' },\n    records: [\n        { recordid: 0, userid: 0, data: 'toaster' },\n        { recordid: 5, userid: 0, data: 'couch' }\n    ]\n}\n{\n    user: { userid: 1, name: 'bob' },\n    records: [\n        { recordid: 2, userid: 1, data: 'television' },\n        { recordid: 9, userid: 1, data: 'air conditioner' }\n    ]\n}\n{\n    user: { userid: 2, name: 'alice' },\n    records: [\n        { recordid: 1, userid: 2, data: 'fridge' },\n        { recordid: 4, userid: 2, data: 'stove' },\n        { recordid: 6, userid: 2, data: 'computer' },\n        { recordid: 7, userid: 2, data: 'washing machine' }\n    ]\n}\n{\n    user: { userid: 3, name: 'roger' },\n    records: [\n        { recordid: 8, userid: 3, data: 'remote control' }\n    ]\n}\n```\n\u003ca name=\"Keywords\"\u003e\u003c/a\u003e\n\n## Keywords\n\nThe following are the keywords supported by LinqBox. Most existing C# LINQ queries should trivially map to LinqBox with minimal changes. The following table lists them all with links to the official Microsoft documentation for additional information on how to use them. All are identical to the C# counterparts with the exception of `let` which has been renamed to `const` due to `let` having conflicting readonly semantics in C# that wouldn't make sense in JavaScript.\n\n\u003ctable\u003e\n    \u003cthead\u003e\n        \u003ctr\u003e\n            \u003cth\u003eClause\u003c/th\u003e\n            \u003cth\u003eDescription\u003c/th\u003e\n        \u003c/tr\u003e\n    \u003c/thead\u003e\n    \u003ctbody\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/from-clause\"\u003efrom\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eSpecifies a data source and a range variable (similar to an iteration variable).\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/where-clause\"\u003ewhere\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eFilters source elements based on one or more boolean expressions separated by logical AND and OR operators or for truthyness.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/select-clause\"\u003eselect\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eSpecifies the type and shape that the elements in the returned sequence will have when the query is executed.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/group-clause\"\u003egroup\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eGroups query results according to a specified key value.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/into\"\u003einto\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eProvides an identifier that can serve as a reference to the results of a join, group or select clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/orderby-clause\"\u003eorderby\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eSorts query results in ascending or descending order based on the default comparer for the element type.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause\"\u003ejoin\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eJoins two data sources based on an equality comparison between two specified matching criteria.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/let-clause\"\u003econst\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eSame as \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/let-clause\"\u003elet\u003c/a\u003e. Introduces a range variable to store sub-expression results in a query expression. \u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/in\"\u003ein\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause\"\u003ejoin\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/on\"\u003eon\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause\"\u003ejoin\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/equals\"\u003eequals\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/join-clause\"\u003ejoin\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/equals\"\u003eby\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/group-clause\"\u003egroup\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/ascending\"\u003eascending\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/orderby-clause\"\u003eorderby\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n        \u003ctr\u003e\n            \u003ctd\u003e\u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/descending\"\u003edescending\u003c/a\u003e\u003c/td\u003e\n            \u003ctd\u003eContextual keyword in a \u003ca href=\"https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/orderby-clause\"\u003eorderby\u003c/a\u003e clause.\u003c/td\u003e\n        \u003c/tr\u003e\n    \u003c/tbody\u003e\n\u003c/table\u003e\n\n\n","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Flinqbox","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsinclairzx81%2Flinqbox","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsinclairzx81%2Flinqbox/lists"}