Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for "limit 0" #2255

Merged
merged 7 commits into from
Jul 23, 2024
Merged

Conversation

sillvva
Copy link
Contributor

@sillvva sillvva commented May 4, 2024

Fixes #2011

MySQL, PostgreSQL, and SQLite all support LIMIT 0 as a way to quickly return an empty dataset. Negative numbers are not supported.

It can be useful for testing queries, but in Drizzle's case, it can also be a simpler way to get conditional nested data without messing up the Typescript return type as demonstrated in #2011

The changes proposed ensure placeholders (object) and numbers >= 0 are still supported. If a developer tries to use a negative number, it would exclude the limit rather than throw an error.

@sillvva sillvva changed the title Add support for "limit 0" feat: add support for "limit 0" May 9, 2024
@AndriiSherman
Copy link
Member

Thanks a lot! It would be awesome if you could add tests for each case. If you need guidance on how to do it, please ping me

@sillvva
Copy link
Contributor Author

sillvva commented Jul 19, 2024

@AndriiSherman This is my first contribution to Drizzle and I have not made tests before, so if you could guide me that would be great.

@AndriiSherman
Copy link
Member

Sure! We have an integration-tests folder that contains all the necessary tests to run. For example, you need to add this test case for PostgreSQL. You would need to use tests/pg/pg-common.ts and add a new test case by following the examples of other test functions you will find. You can get the DB instance, insert some test data, and then test the select with limit and different options. Each test will drop and recreate all tables, so at the start of the test, you will always have empty tables.

Then you can add tests for MySQL and SQLite.

To run tests, navigate to the integration-tests directory and run pnpm run test. This will run all tests, and MySQL and PostgreSQL will create Docker containers for each test case and then drop them after the tests are finished. You can also find vitest.config.ts and include only the specific tests you need, so you won't run all the test cases we have.

@sillvva
Copy link
Contributor Author

sillvva commented Jul 19, 2024

Thanks! I setup a Github Codespace, and ran

pnpm i
pnpm run test

I seem to have all the TS types, so the install looks fine. It's failing before I even added any tests

integration-tests:test:types: cache hit, suppressing logs 9cbf3e41b4b9321c
integration-tests:test: cache miss, executing add336c811a1d10b
integration-tests:test: 
integration-tests:test: > integration-tests@1.0.0 test /workspaces/drizzle-orm/integration-tests
integration-tests:test: > pnpm test:vitest
integration-tests:test: 
integration-tests:test: 
integration-tests:test: > integration-tests@1.0.0 test:vitest /workspaces/drizzle-orm/integration-tests
integration-tests:test: > vitest run
integration-tests:test: 
integration-tests:test: 
integration-tests:test:  RUN  v1.6.0 /workspaces/drizzle-orm/integration-tests
integration-tests:test: 
integration-tests:test:  ❯ tests/mysql/mysql-prefixed.test.ts  (69 tests) 10647ms
integration-tests:test:  ❯ tests/pg/pg-custom.test.ts  (44 tests)
integration-tests:test:  ❯ tests/pg/pg-custom.test.ts  (44 tests) 17373ms
integration-tests:test:  ❯ tests/mysql/mysql-custom.test.ts  (39 tests) 10569ms
integration-tests:test:  ✓ tests/sqlite/sqlite-proxy-batch.test.ts  (8 tests | 1 skipped) 43ms
integration-tests:test:  ❯ tests/pg/neon-http.test.ts  (156 tests | 1 skipped) 1ms
integration-tests:test:  ❯ tests/pg/postgres-js.test.ts  (156 tests) 7161ms
integration-tests:test:  ❯ tests/pg/node-postgres.test.ts  (156 tests) 6818ms
integration-tests:test:  ❯ tests/pg/pg-proxy.test.ts  (153 tests) 6786ms
integration-tests:test:  ❯ tests/sqlite/libsql-batch.test.ts  (7 tests) 1ms
integration-tests:test: (node:39483) ExperimentalWarning: The Ed25519 Web Crypto API algorithm is an experimental feature and might change at any time
integration-tests:test: (Use `node --trace-warnings ...` to show where the warning was created)
integration-tests:test:  ✓ tests/sqlite/d1-batch.test.ts  (7 tests) 487ms
integration-tests:test:  ✓ tests/sqlite/sqlite-proxy.test.ts  (106 tests | 4 skipped) 264ms
integration-tests:test:  ✓ tests/pg/pglite.test.ts  (146 tests | 5 skipped) 9647ms
integration-tests:test:  ❯ tests/mysql/mysql-proxy.test.ts  (129 tests) 10932ms
integration-tests:test:  ✓ tests/sqlite/d1.test.ts  (104 tests | 8 skipped) 762ms
integration-tests:test:  ❯ tests/sqlite/libsql.test.ts  (104 tests) 1ms
integration-tests:test:  ❯ tests/mysql/mysql-planetscale.test.ts  (129 tests | 80 failed | 49 skipped) 11640ms
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table config: unsigned ints
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table config: signed ints
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table config: foreign keys name
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table config: primary keys name
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table configs: unique third param
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > table configs: unique in column
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select all fields
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select typed sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select distinct
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert + select
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > json insert
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert with overridden default values
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert many
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with group by as field
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with exists
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with group by as sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > $default function
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > $default with empty array
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with group by as sql + column
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with group by as column + sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select with group by complex query
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > build query
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > Query check: Insert all defaults in 1 row
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > Query check: Insert all defaults in multiple rows
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > Insert all defaults in 1 row
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > Insert all defaults in multiple rows
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > build query insert with onDuplicate
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert with onDuplicate
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert conflict
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert conflict with ignore
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > partial join with alias
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > full join with alias
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select from alias
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert with spaces
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > prepared statement
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > prepared statement reuse
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > prepared statement with placeholder in .where
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > migrator
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert + select all possible dates
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > Mysql enum test case #1
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > left join (flat object fields)
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > left join (grouped fields)
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > left join (all fields)
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > join subquery
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select from subquery sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select a field without joining its table
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select all fields from subquery without alias
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select for ...
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > view
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select from raw sql
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > select from raw sql with joins
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > join on aliased sql from select
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > prefixed table
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > orderBy with aliased column
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > timestamp timezone
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > transaction rollback
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > nested transaction
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > nested transaction rollback
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > join subquery with join
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > join view as subquery
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert undefined
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > update undefined
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > set operations (union) from query builder with subquery
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > set operations (union) as function
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > set operations (union all) from query builder
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > set operations (union all) as function
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > aggregate function: count
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > aggregate function: avg
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > aggregate function: sum
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > aggregate function: max
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > aggregate function: min
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > mySchema :: select distinct
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > mySchema :: build query
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: serial as id
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: serial as id, batch insert
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: $default as primary key
integration-tests:test:      → fetch failed
integration-tests:test:    ❯ tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: $default as primary key with value
integration-tests:test:      → fetch failed
integration-tests:test:  ❯ tests/mysql/tidb-serverless.test.ts  (129 tests) 1ms
integration-tests:test:  ✓ tests/sqlite/better-sqlite.test.ts  (103 tests | 2 skipped) 225ms
integration-tests:test:  ✓ tests/sqlite/sql-js.test.ts  (103 tests | 2 skipped) 1068ms
integration-tests:test:  ❯ tests/pg/neon-http-batch.test.ts  (1 test)
integration-tests:test:  ❯ tests/mysql/mysql.test.ts  (129 tests) 12069ms
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯ Failed Suites 13 ⎯⎯⎯⎯⎯⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/pg/neon-http-batch.test.ts [ tests/pg/neon-http-batch.test.ts ]
integration-tests:test: Error: NEON_CONNECTION_STRING is not defined
integration-tests:test:  ❯ tests/pg/neon-http-batch.test.ts:40:9
integration-tests:test:      38|  const connectionString = process.env['NEON_CONNECTION_STRING'];
integration-tests:test:      39|  if (!connectionString) {
integration-tests:test:      40|   throw new Error('NEON_CONNECTION_STRING is not defined');
integration-tests:test:        |         ^
integration-tests:test:      41|  }
integration-tests:test:      42|  client = neon(connectionString);
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[1/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/pg/neon-http.test.ts [ tests/pg/neon-http.test.ts ]
integration-tests:test: Error: NEON_CONNECTION_STRING is not defined
integration-tests:test:  ❯ tests/pg/neon-http.test.ts:22:9
integration-tests:test:      20|  const connectionString = process.env['NEON_CONNECTION_STRING'];
integration-tests:test:      21|  if (!connectionString) {
integration-tests:test:      22|   throw new Error('NEON_CONNECTION_STRING is not defined');
integration-tests:test:        |         ^
integration-tests:test:      23|  }
integration-tests:test:      24|  client = neon(connectionString);
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[2/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/pg/node-postgres.test.ts [ tests/pg/node-postgres.test.ts ]
integration-tests:test:  FAIL  tests/pg/pg-proxy.test.ts [ tests/pg/pg-proxy.test.ts ]
integration-tests:test: Error: read ECONNRESET
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { errno: -104, code: 'ECONNRESET', syscall: 'read' }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[3/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/pg/pg-custom.test.ts [ tests/pg/pg-custom.test.ts ]
integration-tests:test: Error: Connection terminated unexpectedly
integration-tests:test:  ❯ Connection.<anonymous> ../node_modules/.pnpm/pg@8.11.5/node_modules/pg/lib/client.js:132:73
integration-tests:test:  ❯ Object.onceWrapper node:events:633:28
integration-tests:test:  ❯ Connection.emit node:events:519:28
integration-tests:test:  ❯ Socket.<anonymous> ../node_modules/.pnpm/pg@8.11.5/node_modules/pg/lib/connection.js:63:12
integration-tests:test:  ❯ Socket.emit node:events:519:28
integration-tests:test:  ❯ TCP.<anonymous> node:net:338:12
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[4/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/pg/postgres-js.test.ts [ tests/pg/postgres-js.test.ts ]
integration-tests:test: Error: read ECONNRESET
integration-tests:test:  ❯ cachedError ../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/query.js:170:23
integration-tests:test:  ❯ new Query ../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/query.js:36:24
integration-tests:test:  ❯ sql ../node_modules/.pnpm/postgres@3.4.4/node_modules/postgres/src/index.js:112:11
integration-tests:test:  ❯ default.retries tests/pg/postgres-js.test.ts:28:9
integration-tests:test:      26|    },
integration-tests:test:      27|   });
integration-tests:test:      28|   await client`select 1`;
integration-tests:test:        |         ^
integration-tests:test:      29|   return client;
integration-tests:test:      30|  }, {
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { errno: -104, code: 'ECONNRESET', syscall: 'read', query: undefined, parameters: undefined, args: [], types: null }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[5/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/mysql-custom.test.ts [ tests/mysql/mysql-custom.test.ts ]
integration-tests:test: Error: Connection lost: The server closed the connection.
integration-tests:test:  ❯ Proxy.createConnection ../node_modules/.pnpm/mysql2@3.3.3/node_modules/mysql2/promise.js:252:31
integration-tests:test:  ❯ default.retries tests/mysql/mysql-custom.test.ts:35:24
integration-tests:test:      33|  const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? aw…
integration-tests:test:      34|  client = await retry(async () => {
integration-tests:test:      35|   client = await mysql.createConnection(connectionString);
integration-tests:test:        |                        ^
integration-tests:test:      36|   await client.connect();
integration-tests:test:      37|   return client;
integration-tests:test:  ❯ RetryOperation.runAttempt [as _fn] ../node_modules/.pnpm/async-retry@1.3.3/node_modules/async-retry/lib/index.js:42:15
integration-tests:test:  ❯ Timeout._onTimeout ../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js:85:10
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { code: 'PROTOCOL_CONNECTION_LOST', errno: undefined, sqlState: undefined }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[6/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/mysql-prefixed.test.ts [ tests/mysql/mysql-prefixed.test.ts ]
integration-tests:test: Error: Connection lost: The server closed the connection.
integration-tests:test:  ❯ Proxy.createConnection ../node_modules/.pnpm/mysql2@3.3.3/node_modules/mysql2/promise.js:252:31
integration-tests:test:  ❯ default.retries tests/mysql/mysql-prefixed.test.ts:39:24
integration-tests:test:      37|  const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? aw…
integration-tests:test:      38|  client = await retry(async () => {
integration-tests:test:      39|   client = await mysql.createConnection(connectionString);
integration-tests:test:        |                        ^
integration-tests:test:      40|   await client.connect();
integration-tests:test:      41|   return client;
integration-tests:test:  ❯ RetryOperation.runAttempt [as _fn] ../node_modules/.pnpm/async-retry@1.3.3/node_modules/async-retry/lib/index.js:42:15
integration-tests:test:  ❯ Timeout._onTimeout ../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js:85:10
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { code: 'PROTOCOL_CONNECTION_LOST', errno: undefined, sqlState: undefined }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[7/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/mysql-proxy.test.ts [ tests/mysql/mysql-proxy.test.ts ]
integration-tests:test: Error: Connection lost: The server closed the connection.
integration-tests:test:  ❯ Proxy.createConnection ../node_modules/.pnpm/mysql2@3.3.3/node_modules/mysql2/promise.js:252:31
integration-tests:test:  ❯ default.retries tests/mysql/mysql-proxy.test.ts:86:24
integration-tests:test:      84|  const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? aw…
integration-tests:test:      85|  client = await retry(async () => {
integration-tests:test:      86|   client = await mysql.createConnection(connectionString);
integration-tests:test:        |                        ^
integration-tests:test:      87|   await client.connect();
integration-tests:test:      88|   return client;
integration-tests:test:  ❯ RetryOperation.runAttempt [as _fn] ../node_modules/.pnpm/async-retry@1.3.3/node_modules/async-retry/lib/index.js:42:15
integration-tests:test:  ❯ Timeout._onTimeout ../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js:85:10
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { code: 'PROTOCOL_CONNECTION_LOST', errno: undefined, sqlState: undefined }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[8/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/mysql.test.ts [ tests/mysql/mysql.test.ts ]
integration-tests:test: Error: Connection lost: The server closed the connection.
integration-tests:test:  ❯ Proxy.createConnection ../node_modules/.pnpm/mysql2@3.3.3/node_modules/mysql2/promise.js:252:31
integration-tests:test:  ❯ default.retries tests/mysql/mysql.test.ts:16:24
integration-tests:test:      14|  const connectionString = process.env['MYSQL_CONNECTION_STRING'] ?? aw…
integration-tests:test:      15|  client = await retry(async () => {
integration-tests:test:      16|   client = await mysql.createConnection(connectionString);
integration-tests:test:        |                        ^
integration-tests:test:      17|   await client.connect();
integration-tests:test:      18|   return client;
integration-tests:test:  ❯ RetryOperation.runAttempt [as _fn] ../node_modules/.pnpm/async-retry@1.3.3/node_modules/async-retry/lib/index.js:42:15
integration-tests:test:  ❯ Timeout._onTimeout ../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js:85:10
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { code: 'PROTOCOL_CONNECTION_LOST', errno: undefined, sqlState: undefined }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[9/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/tidb-serverless.test.ts [ tests/mysql/tidb-serverless.test.ts ]
integration-tests:test: Error: TIDB_CONNECTION_STRING is not set
integration-tests:test:  ❯ tests/mysql/tidb-serverless.test.ts:17:9
integration-tests:test:      15|  const connectionString = process.env['TIDB_CONNECTION_STRING'];
integration-tests:test:      16|  if (!connectionString) {
integration-tests:test:      17|   throw new Error('TIDB_CONNECTION_STRING is not set');
integration-tests:test:        |         ^
integration-tests:test:      18|  }
integration-tests:test:      19| 
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[10/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/sqlite/libsql-batch.test.ts [ tests/sqlite/libsql-batch.test.ts ]
integration-tests:test: Error: LIBSQL_URL is not set
integration-tests:test:  ❯ tests/sqlite/libsql-batch.test.ts:144:9
integration-tests:test:     142|  const authToken = process.env['LIBSQL_AUTH_TOKEN'];
integration-tests:test:     143|  if (!url) {
integration-tests:test:     144|   throw new Error('LIBSQL_URL is not set');
integration-tests:test:        |         ^
integration-tests:test:     145|  }
integration-tests:test:     146|  client = await retry(async () => {
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[11/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/sqlite/libsql-batch.test.ts [ tests/sqlite/libsql-batch.test.ts ]
integration-tests:test: TypeError: Cannot read properties of undefined (reading 'run')
integration-tests:test:  ❯ tests/sqlite/libsql-batch.test.ts:236:11
integration-tests:test:     234| 
integration-tests:test:     235| afterAll(async () => {
integration-tests:test:     236|  await db.run(sql`drop table if exists \`groups\``);
integration-tests:test:        |           ^
integration-tests:test:     237|  await db.run(sql`drop table if exists \`users\``);
integration-tests:test:     238|  await db.run(sql`drop table if exists \`users_to_groups\``);
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[12/94]⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/sqlite/libsql.test.ts [ tests/sqlite/libsql.test.ts ]
integration-tests:test: Error: LIBSQL_URL is not set
integration-tests:test:  ❯ tests/sqlite/libsql.test.ts:19:9
integration-tests:test:      17|  const authToken = process.env['LIBSQL_AUTH_TOKEN'];
integration-tests:test:      18|  if (!url) {
integration-tests:test:      19|   throw new Error('LIBSQL_URL is not set');
integration-tests:test:        |         ^
integration-tests:test:      20|  }
integration-tests:test:      21|  client = await retry(async () => {
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[13/94]⎯
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯ Failed Tests 80 ⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: 
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table config: unsigned ints
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table config: signed ints
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table config: foreign keys name
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table config: primary keys name
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table configs: unique third param
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > table configs: unique in column
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select all fields
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select typed sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select distinct
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert + select
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > json insert
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert with overridden default values
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert many
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with group by as field
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with exists
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with group by as sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > $default function
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > $default with empty array
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with group by as sql + column
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with group by as column + sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select with group by complex query
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > build query
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > Query check: Insert all defaults in 1 row
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > Query check: Insert all defaults in multiple rows
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > Insert all defaults in 1 row
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > Insert all defaults in multiple rows
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > build query insert with onDuplicate
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert with onDuplicate
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert conflict
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert conflict with ignore
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > partial join with alias
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > full join with alias
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select from alias
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert with spaces
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > prepared statement
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > prepared statement reuse
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > prepared statement with placeholder in .where
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > migrator
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert + select all possible dates
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > Mysql enum test case #1
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > left join (flat object fields)
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > left join (grouped fields)
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > left join (all fields)
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > join subquery
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select from subquery sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select a field without joining its table
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select all fields from subquery without alias
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select for ...
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > view
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select from raw sql
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > select from raw sql with joins
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > join on aliased sql from select
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > prefixed table
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > orderBy with aliased column
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > timestamp timezone
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > transaction rollback
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > nested transaction
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > nested transaction rollback
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > join subquery with join
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > join view as subquery
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert undefined
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > update undefined
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > set operations (union) from query builder with subquery
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > set operations (union) as function
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > set operations (union all) from query builder
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > set operations (union all) as function
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > aggregate function: count
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > aggregate function: avg
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > aggregate function: sum
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > aggregate function: max
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > aggregate function: min
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > mySchema :: select distinct
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > mySchema :: build query
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: serial as id
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: serial as id, batch insert
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: $default as primary key
integration-tests:test:  FAIL  tests/mysql/mysql-planetscale.test.ts > common > insert $returningId: $default as primary key with value
integration-tests:test: TypeError: fetch failed
integration-tests:test:  ❯ postJSON ../node_modules/.pnpm/@planetscale+database@1.18.0/node_modules/@planetscale/database/dist/index.js:125:22
integration-tests:test:  ❯ Connection.execute ../node_modules/.pnpm/@planetscale+database@1.18.0/node_modules/@planetscale/database/dist/index.js:81:23
integration-tests:test:  ❯ PlanetScalePreparedQuery.execute ../drizzle-orm/src/planetscale-serverless/session.ts:58:16
integration-tests:test:  ❯ tests/mysql/mysql-common.ts:229:4
integration-tests:test:     227|   beforeEach(async (ctx) => {
integration-tests:test:     228|    const { db } = ctx.mysql;
integration-tests:test:     229|    await db.execute(sql`drop table if exists userstest`);
integration-tests:test:        |    ^
integration-tests:test:     230|    await db.execute(sql`drop table if exists users2`);
integration-tests:test:     231|    await db.execute(sql`drop table if exists cities`);
integration-tests:test: 
integration-tests:test: Caused by: Error: getaddrinfo ENOTFOUND undefined
integration-tests:test:  ❯ GetAddrInfoReqWrap.onlookupall [as oncomplete] node:dns:120:26
integration-tests:test: 
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯
integration-tests:test: Serialized Error: { errno: -3008, code: 'ENOTFOUND', syscall: 'getaddrinfo', hostname: 'undefined' }
integration-tests:test: ⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯⎯[15/94]⎯
integration-tests:test: 
integration-tests:test:  Test Files  14 failed | 7 passed (21)
integration-tests:test:       Tests  80 failed | 555 passed | 72 skipped (1978)
integration-tests:test:    Start at  15:42:06
integration-tests:test:    Duration  112.63s (transform 2.84s, setup 0ms, collect 5.59s, tests 106.50s, environment 0ms, prepare 161ms)
integration-tests:test: 
integration-tests:test:  ELIFECYCLE  Command failed with exit code 1.
integration-tests:test:  ELIFECYCLE  Test failed. See above for more details.
integration-tests:test: ERROR: command finished with error: command (/workspaces/drizzle-orm/integration-tests) pnpm run test exited (1)
integration-tests#test: command (/workspaces/drizzle-orm/integration-tests) pnpm run test exited (1)

 Tasks:    15 successful, 16 total
Cached:    15 cached, 16 total
  Time:    1m57.598s 
Failed:    integration-tests#test

 ERROR  run failed: command  exited (1)
 ELIFECYCLE  Test failed. See above for more details.

I imagine, something like this would be a sufficient test, though, right??

		test('limit 0', async (ctx) => {
			const { db } = ctx.pg;

			await db.insert(usersTable).values({ name: 'John' });
			const users = await db
				.select()
				.from(usersTable)
				.limit(0);

			expect(users).toEqual([]);
		});

@sillvva
Copy link
Contributor Author

sillvva commented Jul 19, 2024

@AndriiSherman I added the tests, but as seen above, they all fail. Even before I added my tests.

261728b

@AndriiSherman
Copy link
Member

@AndriiSherman I added the tests, but as seen above, they all fail. Even before I added my tests.

261728b

I need to fix main branch for tests from forks. I'll do it today and rerun your tests

@AndriiSherman
Copy link
Member

@sillvva, yes, the tests you've sent should be enough for this positive case. You can also add a test with negative numbers in the limit

@AndriiSherman
Copy link
Member

@sillvva, tests should be fixed on our side. It seems like it's a dprint issue now. Could you please format all the files that you changed so they can pass dprint checks?

@sillvva
Copy link
Contributor Author

sillvva commented Jul 22, 2024

@AndriiSherman I formatted it with dprint and pulled your changes, but am still getting mostly failed tests.

@AndriiSherman
Copy link
Member

@AndriiSherman I formatted it with dprint and pulled your changes, but am still getting mostly failed tests.

Please add a .env file to the integration-tests folder with the variable SKIP_EXTERNAL_DB_TESTS=true.

I'll update the CONTRIBUTION guide with this information

@AndriiSherman
Copy link
Member

But the tests seem to pass, so this is mostly for you if you want to make more PRs.

Your commits are not signed, so please sign them in your next PRs. I'll accept this PR without signed commits, but for future ones, please sign them - how to sign commits

@AndriiSherman AndriiSherman merged commit 026b9bb into drizzle-team:main Jul 23, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE]: Add support for LIMIT 0
2 participants