Skip to content
This repository has been archived by the owner on Feb 9, 2023. It is now read-only.

SQL CURD Functions not support #3

Open
willin opened this issue Jun 18, 2020 · 1 comment
Open

SQL CURD Functions not support #3

willin opened this issue Jun 18, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@willin
Copy link
Contributor

willin commented Jun 18, 2020

def:

// import mysqlx from '@mysql/xdevapi';
import mysqlx from 'mysqlx';

const client = mysqlx.getClient(
  {
    host: 'localhost',
    port: 33060,
    user: 'root',
    password: 'root'
  },
  {
    pooling: {
      enabled: true,
      // maxIdleTime: 30000,
      maxSize: 25
      // queueTimeout: 10000
    }
  }
);

main:

const table = session.getSchema('world_x').getTable('city');
  const selected = await table
    .select('ID', 'Name')
    .limit(10)
    .offset(0)
    .execute();
  console.log(selected.fetchAll());

err:

TSError: ⨯ Unable to compile TypeScript:
src/table/index.ts:30:6 - error TS2339: Property 'limit' does not exist on type 'ITableSelect'.

30     .limit(10)
        ~~~~~

    at createTSError (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:434:12)
    at reportTSError (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:438:19)
    at getOutput (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:578:36)
    at Object.compile (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:775:32)
    at Module.m._compile (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:858:43)
    at Module._extensions..js (internal/modules/cjs/loader.js:1220:10)
    at Object.require.extensions.<computed> [as .ts] (/Users/willin/Documents/shiwangme/trial/mysql8/node_modules/ts-node/src/index.ts:861:12)
    at Module.load (internal/modules/cjs/loader.js:1049:32)
    at Function.Module._load (internal/modules/cjs/loader.js:937:14)
    at Module.require (internal/modules/cjs/loader.js:1089:19)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

change it into @mysql/xdevapi, results got:

[
  [
    1,
    'Kabul                                                                                                                                       '
  ],
  [
    2,
    'Qandahar                                                                                                                                    '
  ],
  [
    3,
    'Herat                                                                                                                                       '
  ],
  [
    4,
    'Mazar-e-Sharif                                                                                                                              '
  ],
  [
    5,
    'Amsterdam                                                                                                                                   '
  ],
  [
    6,
    'Rotterdam                                                                                                                                   '
  ],
  [
    7,
    'Haag                                                                                                                                        '
  ],
  [
    8,
    'Utrecht                                                                                                                                     '
  ],
  [
    9,
    'Eindhoven                                                                                                                                   '
  ],
  [
    10,
    'Tilburg                                                                                                                                     '
  ]
]

ref docs: https://dev.mysql.com/doc/x-devapi-userguide/en/sql-crud-functions.html#table-select

p.s.

All chainable functions missing type declaration

@danang-id
Copy link
Owner

@willin Thank you for pointing out about SQL CRUD Functions.

And yes, SQL CRUD Functions has not been implemented, so the error that you got is expected. Not only it does not have type declaration, the wrapper functions is also not yet implemented, thus will create an error when running TypeScript compiling. We would like to implement the SQL CRUD Functions into mysqlx but it will requires quite some time.

For the time being, instead of changing the imports from mysqlx to @mysql/xdevapi, it would be better to get the native @mysql/xdevapi Table object by calling getXTable() function.

On your case example, it would be:

import mysqlx from 'mysqlx';

// client and session definition

const xTable = session.getSchema('world_x').getTable('city').getXTable();
  const selected = await xTable
    .select('ID', 'Name')
    .limit(10)
    .offset(0)
    .execute();
  console.log(selected.fetchAll());

@danang-id danang-id added the enhancement New feature or request label Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants