Skip to content
Merged
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ yarn.lock binary
# paths that don't start with / are relative to the .gitattributes folder
#relative/path/*.txt text eol=lf

src/alasqlparser.js merge=union
src/alasqlparser.js binary


37 changes: 8 additions & 29 deletions .github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,54 +7,33 @@ AlaSQL is an open source SQL database for JavaScript with a focus on query speed
## When Implementing Features

1. **Understand the issue thoroughly** - Read related test cases and existing code
2. **Write a test first** - Create `test/test###.js` for the issue where `###` is the id of the issue we are actually fixing.
2. **Write a test first** - Copy test/test000.js into a new file called `test/test###.js` where where `###` is the id of the issue we are trying to solve
3. **Verify test fails** - Run `yarn test` to confirm the test catches the issue
4. **Implement the fix** - Modify appropriate file(s) in `src/`
5. **Format code** - Run `yarn format` before committing
6. **Verify test passes** - Run `yarn test` again
- If you modify the grammar in `src/alasqlgrammar.jison`, run `yarn jison && yarn test` to regenerate the parser and verify
5. **Reconsider elegance** - Make sure to assess the solution and reconsider if this can be more elegant or efficient
6. **Format code** - Run `yarn format` before committing


## How to to test files
1. Make a test file
- Name new test files as `test/test###.js` where `###` is the GitHub issue number of the issue we are actually fixing.
- If the file already exists we name the file test/test###-B.js
1. Copy the structure in `test/test000.js` as a template
3. Tests should be self-contained and clear about what they're testing
4. Use the Mocha test framework with standard assertions

## SQL Parser Modifications

If a problem demands modifying the lexical parser then seek to do chances as small as possible to `src/alasqlparser.jison`. Afterwards run `yarn jison && yarn test` to confirm the result.

## Commands

```bash
# Install dependencies
yarn

# Generate grammar (if needed)
yarn jison

# Run tests
yarn test

# Format code
yarn format

# Build project
yarn build
```


## Files to Avoid Modifying
- `dist/` - Generated files, will be overwritten on build
- `src/alasqlparser.js` - Generated from Jison grammar (modify the `.jison` file instead)
- `.min.js` files - Generated during build


now commit the code.

## When Reviewing Code

- Verify tests exist for any new functionality and any regression the code changes could have affected.

## Resources

- [AlaSQL Documentation](https://github.com/alasql/alasql/wiki)
- [Issue Tracker](https://github.com/AlaSQL/alasql/issues)
24 changes: 11 additions & 13 deletions test/test000.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@ if (typeof exports === 'object') {
var alasql = require('..');
}

describe('Test 000 - multiple statements', function () {
const test = '000'; // insert test file number
let testId = '000'; // Use the ID of the issue being fixed by this PR

describe(`Test ${testId} - multiple statements`, function () {
before(function () {
alasql('create database test' + test);
alasql('use test' + test);
alasql('create database test' + testId);
alasql('use test' + testId);
});

after(function () {
alasql('drop database test' + test);
alasql('drop database test' + testId);
});

// NOTE: Tests should use assert.deepEqual to verify the complete expected output
// against the actual result object. This ensures comprehensive validation and
// makes test failures more informative by showing the full diff.
// NOTE: Always assert.deepEqual the final and complete output of the last call to alasql

it('A) From single lines', function () {
var res = [];
let res = [];
res.push(alasql('create table one (a int)'));
res.push(alasql('insert into one values (1),(2),(3),(4),(5)'));
res.push(alasql('select * from one'));
Expand All @@ -29,16 +27,16 @@ describe('Test 000 - multiple statements', function () {

it('B) Multiple statements in one string', function () {
//
var sql = 'create table two (a int);';
let sql = 'create table two (a int);';
sql += 'insert into two values (1),(2),(3),(4),(5);';
sql += 'select * from two;';
var res = alasql(sql);
let res = alasql(sql);
assert.deepStrictEqual(res, [1, 5, [{a: 1}, {a: 2}, {a: 3}, {a: 4}, {a: 5}]]);
});

it('C) Multiple statements in one string with callback', function (done) {
// Please note that first parameter (here `done`) must be called if defined - and is needed when testing async code
var sql = 'create table three (a int);';
// use first param (here `done`) when operating with async function or async code
let sql = 'create table three (a int);';
sql += 'insert into three values (1),(2),(3),(4),(5);';
sql += 'select * from three;';
alasql(sql, function (res) {
Expand Down
Loading
Loading