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

sqlite3 statement of create table is empty #2900

Open
hyry1121 opened this issue Nov 10, 2018 · 3 comments
Open

sqlite3 statement of create table is empty #2900

hyry1121 opened this issue Nov 10, 2018 · 3 comments

Comments

@hyry1121
Copy link

hyry1121 commented Nov 10, 2018

Environment

Knex version: ^0.15.2
Database + version: sqlite3^4.0.2
OS: Windows 10, electron^3.0.0

Bug

i'm using vue-cli3 to create an app, and using electron to run the app. following knex examples:

import { remote } from 'electron'

const knex = remote.require('knex')({
  debug: true,
  client: 'sqlite3',
  connection: {
    filename: './mydb.db'
  },
  useNullAsDefault: true
})

knex.schema.createTable( 'users', (table: any) => {
  console.log( 'create...' )
  table.increments( 'id' )
  table.string( 'name' )
}).then( () => {
  console.log( 'insert...' )
  return knex.insert( {name: 'Tim'} ).into( 'users' )
}).then( () => {
  console.log( 'select...' )
  return knex('users').select( 'name' )
}).catch( err => console.error(err) )

then, i got an error:

create...
Error: create table `users` () - SQLITE_ERROR: near ")": syntax error

it looks like the sql create table statement is empty, so i log the sql with .toSQL() :

console.log(
  knex.schema.createTable( 'users', (table: any) => {
    console.log( 'create...' )
    table.increments( 'id' )
    table.string( 'name' )
  }).toSQL()
)

and it shows:

[
  {
    bindings: [],
    sql: "create table `users` ()"
  }
]

i have searched the issues, but got nothing :(
and forgive my poor english :)

@elhigu
Copy link
Member

elhigu commented Nov 10, 2018

Seems strange. Does it have compilation phase to see what kind on js is generated from that type script. And try to debug what kind of object is passed to createTable callback function (console.dir(table)).

@hyry1121
Copy link
Author

@elhigu thanks for the reply !
I took the same code from main.ts(vue entry, also electron render) to main.js(electron main), and changed some ts syntax to js(eg: (table: any) => {} --> (table) => {}). It works! So i think the problem is about electron render, because i use electron.remote.require to require knex in main.ts.

Console.dir(table) in main.ts shows:

{
  bigIncrements: (...),
  bigInteger: (...),
  bigincrements: (...),
  ...
  _method: "create",
  _schemaName: undefined
  _single: {}
  _statements: [
    { builder: {..., _method:"add", _type:"increments", _statements:[]}, grouping: "columns" },
    { builder: {..., _method:"add", _type:"varchar", _statements:[]}, grouping: "columns" }
  ]
  _tableName: "users"
}

All functions of this object show:

[[Handler]]: Object
[[Target]]: ƒ (...args)  remoteMemberFunction
[[IsRevoked]]: false

Before knex, i used sequelize^4.39.0 by electron.remote.require in main.ts, and it worked. Now i delete all code about sequelize, but there is a problem in knex.
Moreover, Does it relate to webpack ? The webpack config is default by vue-cli, i juse change :

config.target = 'electron-renderer'
config.node = false

@kibertoad
Copy link
Collaborator

Likely to be similar to #4194

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants