text:
Comment commands like gcc and gc{motion} do not work within kickstart.nvim

Problem
Comment commands within kickstart.nvim partially do not work (empty checkboxes indicate issues):

[ ] gcc
[ ] gc{motion}
[x] {Visual}gc

Steps to Reproduce

Install kickstart.nvim.

Add the following to your configuration:

-- ...

require('lazy').setup {

  {
    'Wansmer/langmapper.nvim',
    lazy = false,
    priority = 1, -- High priority is needed if you will use `autoremap()`
    config = function()
      local function escape(str)
        -- You need to escape these characters to work correctly
        local escape_chars = [[;,."|\]]
        return vim.fn.escape(str, escape_chars)
      end

      -- Recommended to use lua template string
      local en = [[`qwertyuiop[]asdfghjkl;'zxcvbnm]]
      local ru = [[ёйцукенгшщзхъфывапролджэячсмить]]
      local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>]]
      local ru_shift = [[ËЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ]]

      vim.opt.langmap = vim.fn.join({
          -- | `to` should be first     | `from` should be second
          escape(ru_shift) .. ';' .. escape(en_shift),
          escape(ru) .. ';' .. escape(en),
      }, ',')

      require('langmapper').setup({--[[ your config ]]})
    end,
  },

-- ...

require('langmapper').automapping({ buffer = false })

-- The line beneath this is called `modeline`. See `:help modeline`
--- vim: ts=2 sts=2 sw=2 et

Solution
You can resolve this issue in one of two ways:

Use global automapping

require('langmapper').automapping({ global = true, buffer = false })

-- The line beneath this is called `modeline`. See `:help modeline`
--- vim: ts=2 sts=2 sw=2 et

Use automapping in the configuration of the echasnovski/mini.nvim plugin

Click to expand
-- ...

{ -- Collection of various small independent plugins/modules
    'echasnovski/mini.nvim',
    config = function()
      -- Better Around/Inside textobjects
      --
      -- Examples:
      --  - va)  - [V]isually select [A]round [)]paren
      --  - yinq - [Y]ank [I]nside [N]ext [Q]uote
      --  - ci'  - [C]hange [I]nside [']quote
      require('mini.ai').setup { n_lines = 500 }

      -- Add/delete/replace surroundings (brackets, quotes, etc.)
      --
      -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
      -- - sd'   - [S]urround [D]elete [']quotes
      -- - sr)'  - [S]urround [R]eplace [)] [']
      require('mini.surround').setup()

      -- Simple and easy statusline.
      --  You could remove this setup call if you don't like it,
      --  and try some other statusline plugin
      local statusline = require 'mini.statusline'
      -- set use_icons to true if you have a Nerd Font
      statusline.setup { use_icons = vim.g.have_nerd_font }

      -- You can configure sections in the statusline by overriding their
      -- default behavior. For example, here we set the section for
      -- cursor location to LINE:COLUMN
      ---@diagnostic disable-next-line: duplicate-set-field
      statusline.section_location = function()
        return '%2l:%-2v'
      end

      -- ... and there is more!
      --  Check out: https://github.com/echasnovski/mini.nvim

      -- ADD THIS LINE
      -- ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
      require('langmapper').automapping({ buffer = false })
    end,
  },

  -- ...

Note to Author
You can close this issue as solved.

Solution
You can resolve this issue in one of two ways:

Use global automapping

require('langmapper').automapping({ global = true, buffer = false })

-- The line beneath this is called `modeline`. See `:help modeline`
--- vim: ts=2 sts=2 sw=2 et

Use automapping in the configuration of the echasnovski/mini.nvim plugin

Click to expand
-- ...

{ -- Collection of various small independent plugins/modules
    'echasnovski/mini.nvim',
    config = function()
      -- Better Around/Inside textobjects
      --
      -- Examples:
      --  - va)  - [V]isually select [A]round [)]paren
      --  - yinq - [Y]ank [I]nside [N]ext [Q]uote
      --  - ci'  - [C]hange [I]nside [']quote
      require('mini.ai').setup { n_lines = 500 }

      -- Add/delete/replace surroundings (brackets, quotes, etc.)
      --
      -- - saiw) - [S]urround [A]dd [I]nner [W]ord [)]Paren
      -- - sd'   - [S]urround [D]elete [']quotes
      -- - sr)'  - [S]urround [R]eplace [)] [']
      require('mini.surround').setup()

      -- Simple and easy statusline.
      --  You could remove this setup call if you don't like it,
      --  and try some other statusline plugin
      local statusline = require 'mini.statusline'
      -- set use_icons to true if you have a Nerd Font
      statusline.setup { use_icons = vim.g.have_nerd_font }

      -- You can configure sections in the statusline by overriding their
      -- default behavior. For example, here we set the section for
      -- cursor location to LINE:COLUMN
      ---@diagnostic disable-next-line: duplicate-set-field
      statusline.section_location = function()
        return '%2l:%-2v'
      end

      -- ... and there is more!
      --  Check out: https://github.com/echasnovski/mini.nvim

      -- ADD THIS LINE
      -- ⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄⌄
      require('langmapper').automapping({ buffer = false })
    end,
  },

  -- ...

There are many plugins in kickstart.nvim that can affect the setting of key bindings. The default gcc and gc works together with langmapeer on an empty config.
To continue working on this issue, please provide the minimal config where the problem is reproduced (not the whole kickstart.nvim).

local lazypath = vim.fn.stdpath 'data' .. '/lazy/lazy.nvim'
if not (vim.uv or vim.loop).fs_stat(lazypath) then
  local lazyrepo = 'https://github.com/folke/lazy.nvim.git'
  local out = vim.fn.system { 'git', 'clone', '--filter=blob:none', '--branch=stable', lazyrepo, lazypath }
  if vim.v.shell_error ~= 0 then
    error('Error cloning lazy.nvim:\n' .. out)
  end
end ---@diagnostic disable-next-line: undefined-field
vim.opt.rtp:prepend(lazypath)

vim.opt.number = true

require('lazy').setup({

  {
    'Wansmer/langmapper.nvim',
    lazy = false,
    priority = 1, -- High priority is needed if you will use `autoremap()`
    init = function()
      local function escape(str)
        -- You need to escape these characters to work correctly
        local escape_chars = [[;,."|\]]
        return vim.fn.escape(str, escape_chars)
      end

      -- Recommended to use lua template string
      local en = [[`qwertyuiop[]asdfghjkl;'zxcvbnm]]
      local ru = [[ёйцукенгшщзхъфывапролджэячсмить]]
      local en_shift = [[~QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>]]
      local ru_shift = [[ËЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ]]

      vim.opt.langmap = vim.fn.join({
        -- | `to` should be first     | `from` should be second
        escape(ru_shift) .. ';' .. escape(en_shift),
        escape(ru) .. ';' .. escape(en),
      }, ',')
    end,
    config = function()
      require('langmapper').setup {}
      require('langmapper').hack_get_keymap()
    end,
  },

  {
    'folke/which-key.nvim',
    -- event = 'VimEnter',
  },

})

require('langmapper').automapping { buffer = false }

-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et

So, this is because you using which-key. Trying this solution: https://github.com/Wansmer/langmapper.nvim/discussions/11#discussioncomment-11210683
I close the issue because it is not related to langmapper, but to an external dependency

authors: Wansmer drowning-cat


text:
env.ini

Hello, thank you for sharing your amazing work!
I've an issue, I'm unable to load the page, it automatically redirect to ./public/{local}/notsupported page.
I addressed the issue to env.ini file location, probably. As you can see it's unable to "convert" $ENV into "assets/" position.
I tried to place env.ini everywhere without success.
Any hint ?
Thanks

The value of the path setting should be:

The env.ini file should be in the root directory where the composer.json file is located.

The value of the path setting should be:
The env.ini file should be in the root directory where the composer.json file is located.

I've done that, but nothing changed.
I tried to restart the server, re-compile it, but nothing.

I modified the file config.ini located in app/config

deleted the browser cache, and now it works :D
Thank you again for your work!

source: gharchive/issue

repo: Warsaalk/trashsim-public

license: MIT

license_type: permissive

license_source: github-api


text:
[DOCS] missing crun instructions in https://wasmedge.org/docs/develop/deploy/podman/#prerequisites

Description
Summary
Step 3 of https://wasmedge.org/docs/develop/deploy/podman/#prerequisites: It seems like some instructions are missing.
Build and configure crun with WasmEdge support
Next, configure and build a crun binary with WasmEdge support.
Maybe there should be a git clone, similar to https://wasmedge.org/docs/develop/deploy/oci-runtime/crun/#prerequisites?
Issue refers to:
https://github.com/WasmEdge/WasmEdge/issues/3028
Screenshots
No response
Additional information
No response

I'll work on this

repo: WasmEdge/docs


text:
Consider putting bucket paths outside the script

Relates to #1
Maybe as env variable. Maybe target path (workspace) also deserves that.

Done due to change in approach for handling workflow

repo: WaterlinePL/project-download-job


text:
工作流中数据开发组件关联脚本选项，选择脚本后提示关联脚本失败 NullPointerException

Describe the bug
工作流中数据开发组件关联脚本选项，选择脚本后提示关联脚本失败 NullPointerException

../dss_linkis/linkis/linkis-publicservice/logs/linkis.log   有如下异常提示

linkis版本0.11.0  dss版本0.9.0

同样的问题，DSS0.9.1 \ linkis0.9.4

Hello, this problem has been solved in DSS DSS-230

authors: lordk911 peacewong zoneyeah

repo: WeBankFinTech/Linkis


text:
Add one key flow example

Adds the one key flow example for Web3Auth. This works using firebase.

Things to note while documenting: Need to understand how the users are being classified - accordingly when to call torus libraries and when to call web3auth. webpack config changes. this works only on custom verifiers, with custom jwts - why.

source: gharchive/pull-request


text:
Create pritamnegi.txt

This Pull Request resolves Issue #1

Thanks for contributing!

license: mit

license_source: bigquery


text:
🛑 SSO is down

In b6365a5, SSO (https://sso.zeltik.es/auth) was down:

HTTP code: 0
Response time: 0 ms

Resolved: SSO is back up in 883f317.

repo: Webdeporte/statuspage


text:
w-include - dynamic path

User variables as include path.

The child (included) template should be parsed by passing local-scope and global-scope variables to it. The result of that should be put in place of the w-include tag.

repo: Webiny/Htpl


text:
How can I get email from attribute object?

Hello,
I need to get the email from Webklex\PHPIMAP\Attribute, when I die my object dd($this->email->from) I got this:
Webklex\PHPIMAP\Attribute^ {#844
  #name: ? string
  #values: []
  +"0": Webklex\PHPIMAP\Address^ {#849
    +personal: "Kouceyla Hadji"
    +mailbox: "kouceyla"
    +host: "domain.com"
    +mail: "kouceyla@domain.com"
    +full: "Kouceyla Hadji <kouceyla@domain.com>"
  }
}

I need to get "mail"

Would be $this->email->getFrom()->first()->mail in your case. Cheers :)

Thanks :)

repo: Webklex/php-imap


text:
Add external/custom fonts

How to add custom font files?

https://gist.github.com/Turbo87/e8e941e68308d3b40ef6

Following the original starter project, it's updated and they resolve issues
https://github.com/AngularClass/angular2-webpack-starter


text:
Could not load file or assembly Col.Mod.Better.Shared

Hello, I'm not able to load this mod in the latest version of the game. Folder name checks, all vanilla, integrity checked. Log attached.
22-10-16_18-06-36_9583.log

You has not copy "Col.Mod.Better.Shared.dll" in mod root directory. Add the file from last realease and is working.
This mod hasnt assets.

Log please.

i get the same error mentioned in the beginning, the .shared.dll file does exist in the coi.mod.better folder as downloaded in the release
22-10-27_06-04-00_3357.log

I am getting the same error as well with new save.

authors: Cengro Wehmeyer100 adiamaq askewdread


text:
trying eqwalizer on elixir projects

We wanted to try eqwalizer on our elixir projects. I know it would be a lot better to implement a parser for Elixir projects, but as a first step we decompiled the beam files to erlang sources, and
we were running eqwalizer on those sources.
We have found some problems:

in the decompiled source there is a -file attribute:

-file("lib/asdfqqqq.ex", 1).
-module('Elixir.Asdfqqqq').

When this attribute is there eqwalizer simply ignores all problems. If I manually delete this line, it works.

there is also an info/1 function in the source:

'__info__'(module) -> 'Elixir.Asdfqqqq';
'__info__'(functions) -> [{double, 1}];
'__info__'(macros) -> [];
'__info__'(exports_md5) -> <<"\035S8}I7\030\232\236g-\023">>;

this last function clause will cause this problem:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Utf8Error { valid_up_to: 429, error_len: Some(1) }', crates/elp/src/bin/[reporting.rs:101](http://reporting.rs:101/):78
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

actually, when I manually fix these problems eqwalizer works quite well, and it is able to spot the problems in the code (of course the line numbers are wrong). One remaining problem is that I could not figure out how to tell to eqwalizer where the declarations of Elixir types are. So for instance:

-spec double({error, 1}) -> 'Elixir.String':t().
double(_x@1) -> 2 * _x@1.

Elixir.String type is declared in $ELIXIR_DIR//lib/elixir/lib/string.ex. Similarly, I want to add all files where elixir types are declared. How can I add those using project.json?
I have one more question...
Let's say I have my_app application, which uses my_lib as a dependency. In my_app.erl I have the following:
-include_lib("my_lib/include/my_lib.hrl").

I've tried it with this project.json:
{
  "apps": [
    {
      "name": "my_app",
      "dir": "",
      "ebin": "_build/default/lib/my_app/ebin",
      "extra_src_dirs": [""],
      "include_dirs": ["include"],
      "macros": ["TEST"],
      "src_dirs": ["src"]
    }
  ],
  "deps": [
    {
      "name": "my_lib",
      "dir": "",
      "ebin": "_build/default/lib/my_lib/ebin",
      "extra_src_dirs": [""],
      "include_dirs": ["_build/default/lib/my_lib/include"],
      "macros": ["TEST"],
      "src_dirs": ["src"]
    }

  ],
  "root": ""
}

elp is still complaining about being not able to find the include file:
  eqWAlizing                ████████████████████ 3/3                                                                             error: parse_error
    ┌─ src/my_app.erl:3:14
    │
103 │ -include_lib("my_lib/include/my_lib.hrl").
    │              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find include lib "my_lib/include/my_lib.hrl"

Do you have an idea what should I put into my project.json ?

We were trying to make it work using the following project.json :
{
  "apps": [
    {
      "name": "asdfqqqq",
      "dir": "/home/joe/Projects/asdfqqqq",
      "ebin": "/home/joe/Projects/asdfqqqq/_build/dev/lib/asdfqqqq/ebin",
      "extra_src_dirs": ["test"],
      "include_dirs": ["include"],
      "macros": ["TEST"],
      "src_dirs": ["erlangized_src/"]
    }
  ],
  "deps": [
    {
      "name": "elixir",
      "dir": "/home/joe/.manager/elixir",
      "ebin": "/home/joe/.managerl/erlang-OTP-23.2.3/elixirs/elixir-v1.12.2/lib/elixir/lib/elixir/ebin",
      "extra_src_dirs": [],
      "include_dirs": [],
      "macros": [],
      "src_dirs": ["lib"]
    }

  ],
  "source_root": "/home/joe/Projects/asdfqqqq",
  "otp_lib_dir": "/home/joe/.managerl/erlang-OTP-23.2.3/lib/"
}

Elixir.String.t() type is declared in the above-mentioned folder. With these settings, it still was not able to find the declaration of this type. Is it possible that to find the declaration eqwalizer also needs the erlang source code present in the src directory, or do you have any other ideas on what's going on wrong?

We don't provide any support for type-checking Elixir projects out of the box and we don't plan to do it on our own in the near future
Nevertheless, I think that it's feasible to to use it for Elixir, - but someone needs to drive it. And it's hard to estimate the amount of tech work.

Contributions are welcome.

authors: ilya-klyuchnikov tothlac

repo: WhatsApp/eqwalizer


text:
Trademark infringement complain from enf.whatsapp.2548904@enf-meta.com

A few month ago I developed any app Status Saver to save WhatsApp Status but I got
Trademark Owner:
WhatsApp LLC
Complainant Email:
enf.whatsapp.2548904@enf-meta.com
Complainant Details:
The app uses the trademarks, banners, badges and logos of WhatsApp without authorization, including, but not limited to, the use of ley elements of WhatsApp's Famous Trademarked Logo in the app's icon. The developer’s use of WhatsApp's trademarks in app’s title and/or icon implies an association or other relationship that is neither authorized nor endorsed by WhatsApp.
I tried to contact them throw email but it has been 5 days but no reply from WhatsApp LLC.  I am ready to do all required changes in app. I have done lots of hard work to develop this app. Please help me out.

Hi!
This repo is specifically for proxy related issues and I am not familiar with the infringement complain process unfortunately. I'll close this task.

repo: WhatsApp/proxy


text:
🛑 Munin is down

In e706e0c, Munin (https://munin.wicloz.rocks/) was down:

HTTP code: 0
Response time: 0 ms

Resolved: Munin is back up in 3e7b96c after 10 minutes.

repo: Wicloz/upptime


text:
Add color functions, improve variables and imports

imports now work in any place in file (i. e. Numix used to use this, see v2.0)
variables logic heavily rewritten (based on postcss-simple-vars)
color functions, powered by postcss-functions
migrate to ES6, add babel
switch ESLint config to better suit your style :)

Thank you for your contribution! If you want to continue contributing to this project, keep in mind that I am only aiming for GTK 3.20 compatibility right now. There have been made some big GTK CSS changes in this new version, so backward compatibility with older theme files is too complicated to be top priority.

authors: Wietsedv iamale

repo: Wietsedv/postcss-web-gtk


text:
added support for custom React ID Attribute

This commit adds support for cases when React is changed to use a custom React ID attribute. In browserify, the react ID can be changed as follows:
require('react/lib/DOMProperty').ID_ATTRIBUTE_NAME = 'data-reactid-...';
So this commit makes sure that ReactShadow gets the right ID Attribute in case its running as a commonjs module

Thanks @ziahamza! :+1:

authors: Wildhoney ziahamza

repo: Wildhoney/ReactShadow


text:
Black and White Output

Hello William! Congratulations, this is a wonderfull script. Well I found something interesting and related with the issue #11 . Every time the program runs, it outputs a mask with only one chanel. That's why it generates black and white images.  This is intentional? Thank you very much for this library!

Yes, it's generating a mask. You need to apply a bitwise operator to produce a coloured image. You can find more on stackoverflow.
StackOverflow - opencv-apply-mask-to-a-color-image

authors: Valdecy WillBrennan

repo: WillBrennan/SkinDetector


text:
Exception: Unclosed quoted field on line 4.

So here's a random edge case... winrm-fs fails when there's an "All Users, All Hosts" type of powershell profile that writes output on the target node. winrm-fs cannot parse the response as CSV successfully because the values written out in the profile will most likely not be properly comma separated.
The fix would probably be to run the script without loading a profile, using the -noprofile switch when calling PowerShell.. but that call appears to be in the winrm definition. So maybe this issue should be logged there?
Anyway... The fix for me is to just remove the write-output from my profile.
To recreate the issue:

get a "destination", for me I just did kitchen create any windows host will work
create a powershell profile script in the remote node's $PSHome directory..
run kitchen converge or some other command that uses the function parse_response

`C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps`` >
Write-Output 'Hello!!'

Run kitchen converge
Here's the trace:
D      [WinRM] opening remote shell on http://10.12.235.80:5985/wsman
D      [WinRM] remote shell 70A3F068-8133-44F6-9C38-4F8FAA875DDE is open on http://10.12.235.80:5985/wsman
D      creating hash for file $env:TEMP/default-Windows-long_script.ps1
D      Running check_files.ps1
D      @{
D        "67907d49d035159f3f525a8fbf5c5368" = @{
D          "target" = "$env:TEMP/default-Windows-long_script.ps1";
D          "src_basename" = "default-Windows-long_script.ps1";
D          "dst" = "$env:TEMP/default-Windows-long_script.ps1"
D        }
D      }
D      Parsing CSV Response
D      Resetting $HOMEDRIVE & $HOMEPATH for you...
Initializing the chef shell...
All set!
"chk_exists","src_md5","dst_md5","chk_dirty","verifies","target_is_folder"
"True","67907d49d035159f3f525a8fbf5c5368","67907d49d035159f3f525a8fbf5c5368","False","True","False"

D      Cleaning up local sandbox in C:/Users/nhudacin/AppData/Local/Temp/default-Windows-sandbox-20160824-9900-1eijbbu
>>>>>> ------Exception-------
>>>>>> Class: Kitchen::ActionFailed
>>>>>> Message: 1 actions failed.
>>>>>>     Failed to complete #converge action: [Unclosed quoted field on line 4.] on default-Windows
>>>>>> ----------------------
>>>>>> Please see .kitchen/logs/kitchen.log for more details
>>>>>> Also try running `kitchen diagnose --all` for configuration

D      ------Exception-------
D      Class: Kitchen::ActionFailed
D      Message: 1 actions failed.
>>>>>>     Failed to complete #converge action: [Unclosed quoted field on line 4.] on default-Windows
D      ----------------------
D      ------Backtrace-------
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:187:in `report_errors'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:178:in `run_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command/action.rb:39:in `block in call'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command/action.rb:37:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/cli.rb:56:in `perform'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/cli.rb:185:in `block (2 levels) in <class:CLI>'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/cli.rb:326:in `invoke_task'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/bin/kitchen:13:in `block in <top (required)>'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/errors.rb:174:in `with_friendly_errors'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/bin/kitchen:13:in `<top (required)>'
D      C:/opscode/chefdk/bin/kitchen:21:in `load'
D      C:/opscode/chefdk/bin/kitchen:21:in `<main>'
D      ----End Backtrace-----
D      -Composite Exception--
D      Class: Kitchen::ActionFailed
D      Message: Failed to complete #converge action: [Unclosed quoted field on line 4.] on default-Windows
D      ----------------------
D      ------Backtrace-------
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1872:in `block in shift'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1779:in `loop'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1779:in `shift'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1721:in `each'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1735:in `to_a'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1735:in `read'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1293:in `parse'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:404:in `parse_response'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:203:in `check_files'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:80:in `block in upload'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:78:in `upload'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:134:in `upload'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:394:in `run_from_file_command'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:102:in `execute'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/provisioner/base.rb:72:in `block in call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/base.rb:94:in `initialize'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:470:in `new'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:470:in `create_new_connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:74:in `connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/provisioner/base.rb:71:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:373:in `block in converge_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:513:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:513:in `synchronize_or_call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:478:in `block in action'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:477:in `action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:369:in `converge_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:348:in `block in transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:347:in `each'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:347:in `transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:138:in `converge'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:201:in `public_send'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:201:in `run_action_in_thread'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:173:in `block (2 levels) in run_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `block in create_with_logging_context'
D      ----End Backtrace-----
D      ---Nested Exception---
D      Class: Kitchen::ActionFailed
D      Message: Failed to complete #converge action: [Unclosed quoted field on line 4.]
D      ----------------------
D      ------Backtrace-------
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1872:in `block in shift'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1779:in `loop'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1779:in `shift'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1721:in `each'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1735:in `to_a'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1735:in `read'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/csv.rb:1293:in `parse'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:404:in `parse_response'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:203:in `check_files'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:80:in `block in upload'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/winrm-fs-0.4.3/lib/winrm-fs/core/file_transporter.rb:78:in `upload'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:134:in `upload'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:394:in `run_from_file_command'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:102:in `execute'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/provisioner/base.rb:72:in `block in call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/base.rb:94:in `initialize'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:470:in `new'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:470:in `create_new_connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/transport/winrm.rb:74:in `connection'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/provisioner/base.rb:71:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:373:in `block in converge_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:513:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:513:in `synchronize_or_call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:478:in `block in action'
D      C:/opscode/chefdk/embedded/lib/ruby/2.1.0/benchmark.rb:279:in `measure'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:477:in `action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:369:in `converge_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:348:in `block in transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:347:in `each'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:347:in `transition_to'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/instance.rb:138:in `converge'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:201:in `public_send'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:201:in `run_action_in_thread'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/test-kitchen-1.11.1/lib/kitchen/command.rb:173:in `block (2 levels) in run_action'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `call'
D      C:/opscode/chefdk/embedded/lib/ruby/gems/2.1.0/gems/logging-2.1.0/lib/logging/diagnostic_context.rb:450:in `block in create_with_logging_context'
D      ----End Backtrace-----
D      [WinRM] closing remote shell 70A3F068-8133-44F6-9C38-4F8FAA875DDE on http://10.12.235.80:5985/wsman
D      [WinRM] remote shell 70A3F068-8133-44F6-9C38-4F8FAA875DDE closed
PS C:\_source\git\cookbook-consilio-chefdk>

Interesting. Yes we really should be specifying -noprofile in winrm. However we are on the verge of releasing winrm v2 which uses true powershell tempting and does not load user profiles.

authors: mwrock nhudacin

repo: WinRb/winrm-fs


text:
Fixed issue 2 - upload a dir multiple times

Fixed issue 2 and redesigned how file upload works and reduced a lot of duplication.

Added PowerShell scripts and templating
Fixed multiple directory uploads and directory dirty checking
Collapsed file decoding to a single script
Use deterministic paths for temp files.

Externalizing as .ps1.erb is an improvement, but getting it to be pure powershell (by using powershell parameters to avoid the need for ERB variables) would be even better.

@maxlinc Now that you mention using PS args, yes that would be a nice improvement.

authors: maxlinc sneal


text:
Why isn't there a designer WYSIWYG for Hamburger menu items?

Other than the image for the hamburger itself, there doesn't seem to be a designer view of Hamburger menu items and button icons.  I was hoping it would render similar to Windows Phone ApplicationBar which has a design-time view.
Is the only option at the moment to handcode XAML and view the results at runtime?
Thanks,
Rick

There is a designer view (in Minimal template at least). Look in Shell.xaml. That's where the hamburger menu is coded, so the design-time view is in there.
Unfortunately, due to the way T10 does things, I don't think there is a way to see the hamburger menu over any of your pages at design-time.

Not sure what could be done different at this point.

authors: JerryNixon callummoffat rickengle


text:
Help me use SQLite!

General Help Thread
This thread is for anyone who needs help using SQLite or Node.js with regards to better-sqlite3.
It's common for issues to appear with titles like "Help me do ABC" or "How do I build an app like XYZ?". These types of issues aren't real issues with better-sqlite3, so they will be closed and considered a duplicated of this thread. Therefore, post your questions here instead. If you're lucky, friendly members of the community may chime in here to help you.

By default, SQLite is very bad at performing concurrent reads and writes. However, performance can be improved tremendously by activating WAL mode.
db.pragma('journal_mode = WAL');

For more information, read here.

Is it possible to insert multiple rows from an array of objects? Say I have this:
var data = [
    { foo: 1, bar: 2 },
    { foo: 3, bar: 4 }
];

I'd like to be able to do this:
db.prepare('INSERT INTO baz VALUES ($foo, $bar)').run(data);

Not sure if running INSERT statements in a loop is efficient.
As a side note, sqlite does does support insertion of multiple values.
Eg, INSERT INTO baz VALUES (1, 2), (3, 4) will insert 2 rows.

Using a loop is quite efficient, @dimitry-ishenko.
There are two things to be aware of:

you should prepare the statement only once, and run it multiple times
you can further increase performance by wrapping the loop in a transaction (BEGIN...COMMIT)

to learn how to use manual transactions, see here.

Here's an example of what (I believe) you're trying to do:
const insert = db.prepare('INSERT INTO baz VALUES ($foo, $bar)');
const insertMany = asTransaction((data) => {
  for (const obj of data) insert.run(obj);
});

insertMany([
    { foo: 1, bar: 2 },
    { foo: 3, bar: 4 }
]);

Hi, I am curious about the performance of the method you just mentioned @JoshuaWise. How does this compare to actually running a batch write? The tradeoff being if the insertMany method below cannot use a prepared statement.
const insertMany = data => {
  const valuesStr = Array(data.length).fill('(?, ?)').join(',')
  const sql = `INSERT INTO baz VALUES ${valuesStr}`
  const flattened = data.reduce((acc, d) => {
    acc.push(Object.values(d))
    return acc
  }, [])
  db.run(sql, flattened)
}

when comparing the two executing directly like so cat insert-many.sql | sqlite3 I believe my method would win out. Wrapped in better-sqlite though, is it faster to run many inserts as opposed to batching to avoid preparing the statement each time?

Hi, can i just use the prepare statement + run statement for creating tables or creating trigger?
const statement = db.prepare('CREATE TABLE IF NOT EXISTS ? (?)');
{some foo}
statement.run(tableName, tableColumns);

@Nikumarekko the only thing wrong with your code is that SQLite3 does not allow you to bind strings for identifier names (such as table or column names). You can only use bound values for actual run-time values.
// No bound parameters for table/column names
const createTable = db.prepare(`CREATE TABLE IF NOT EXISTS  ${tableName} (${tableColumns})`);
createTable.run();

// Use bound parameters for actual strings
const select = db.prepare(`SELECT * FROM ${tableName} WHERE foo = ?`);
const results = select.all('someString');

Keep in mind that because you have to use string interpolation for table and column names, they should only come from trusted sources.

@Nikumarekko the only thing wrong with your code is that SQLite3 does not allow you to bind strings for identifier names (such as table or column names). You can only use bound values for actual run-time values.
// No bound parameters for table/column names
const createTable = db.prepare(`CREATE TABLE IF NOT EXISTS  ${tableName} (${tableColumns})`);
createTable.run();

// Use bound parameters for actual strings
const select = db.prepare(`SELECT * FROM ${tableName} WHERE foo = ?`);
const results = select.all('someString');

Keep in mind that because you have to use string interpolation for table and column names, they should only come from trusted sources.

Thanks for your quick reply, helps me a lot

I have a file called json.sqlite that stores my data and im not sure how I will VACUUM it.
Also what is the name of my db file if my using quick.db? (quick.db is a wrapper for better-sqlite3)
https://stackoverflow.com/questions/18126997/how-to-vacuum-sqlite-database this is how you vacuum a sqlite file how will i vacuum a better-sqlite3 file?

hi @JoshuaWise
I'm trying to use this module with Express.js but for some reason when I call run on the statement, the http connection gets closed without any error, just upstream prematurely closed connection while reading response header from upstream in nginx log
code is pretty simple
router.post("/path1", function(req, res, next) {
  db.prepare(sqlQuery).run(params);
  res.redirect("/path2");
})

any suggestion how to find the cause of the problem?
thanks

@bombard-kb better-sqlite3 and express don't interact in any way whatsoever. It could be related to a timeout occurring in express, but it likely is completely unrelated to better-sqlite3.

@JoshuaWise it looks like I was trying to use "on conflict statement" with sqlite3 version, which doesn't support it

How do I use better-sqlite3 with a precompile version of SQLite?

@JefStat better-sqlite3 has to be compiled with SQLite as a static library, not a precompiled dynamic library. You can, however, use a custom amalgamation with your own custom compile-time options. Learn how here

Hi
Can I store an image as a Blob in sqlite/better-sqlite3 to then use URL.createObjectURL(blob) for displaying the image in the render window?
As I am a newbie with sqlite, it might as well be a stupid question :-)
I am developing an electron/desktop app where I am storing a lot of images. Before I have used the browsers internal indexeddb where the images were stored as a Blob. I then created an objectURL which I used to display the images in the render window.
As indexeddb is limited in some ways, I came across better-sqlite3. Storing and reading the images as base64 worked like a charm, but I would have hoped that I do not have to shuffle around so much data and can make use of objectURLs.

Can I have table name as a query parameter? For example, in mysql, I can do CREATE TABLE ?? (col1 varchar, ...) with a parameter array of [tableName]. I saw in the API doc you can insert parameters with the standard ? in a query, but how about parameters that are table names? Does that have it's own symbol, like how mysql has ???

Can I store an image as a Blob in sqlite/better-sqlite3

@fakob, you can store any arbitrary data in a Blob, so the answer is yes.

Can I have table name as a query parameter?

@andrewkolos, SQLite3 provides no way of using parameters for table/column names. However, if you properly quote/escape the table name, you can use JavaScript's string interpolation:
function quote(name) {
  return '\x60' + String(name).replace(/\x60/g, '\x60\x60') + '\x60';
}

const stmt = db.prepare(`SELECT * FROM ${quote(tableName)}`);

@JoshuaWise
Thanks for the answer. Though there might be a difference between Blobs stored in sqlite3 compared to the indexedDB database. From Blobs stored in sqlite3 I was not able to create objectURLs with URL.createObjectURL(blob). But maybe I have misunderstood something.

Hi,
I get some 'out of memory errors', I guess because of my use of better-sqlite. I don't know why : https://stackoverflow.com/questions/55657313/out-of-memory-puppeteer-or-better-sqlite3
Any hint ?

so how you guys generally use this in your app?
Is there any tools like query builder so I don't have to maintain sql strings by hand which is error prone imo. I found knex.js only supports node-sqlite3.
cc @JoshuaWise

Hi there,
How would I use a trigger function using better-sqlite to perform a file delete once the row is deleted.
Here's the scenario:
Table: Student
Columns:
id integer (primary key not null)
Name Varchar(30) not null
Table : StudentFiles
Columns :
id integer (primary key not null)
studentFilePath: varchar(200) // this is stored as a json string.
studentId: foreign key references Student.id on delete cascade on update cascade
When a row is deleted from the Student table, the corresponding row will also be removed from the StudentFiles table.
How would I create a trigger to call my javascript function to delete the file as pointed by studentFilePath before the row inside StudentFiles disappear?
Thanks.

@mygithubid1, Here's the basic idea:
const fs = require('fs');
const db = require('better-sqlite3')('data.db');

db.function('delete_file', (filename) => {
  fs.unlinkSync(String(filename));
});

db.exec(`
  CREATE TEMPORARY TRIGGER delete_student_files
  AFTER DELETE ON StudentFiles
  BEGIN
    SELECT delete_file(old.studentFilePath);
  END;
`);

@JoshuaWise Thank you. Will give this a shot.

@JoshuaWise Worked. Thank you.

Hello,
I encountered a problem while executing ATTACH statement.
const attach = this.db.prepare("ATTACH DATABASE '" + databasePath + "' AS temp;")
this.db.exec(attach)

Error 'expected first argument to be a string' is reported.  Does anybody know what is the issue?
databasePath is relative
Best regards,
Igor

@vurdeljica, the db.prepare() function returns a Statement object. To execute a statement, you should use statement.run(). The db.exec() function you're using expects an SQL string, not a statement object.
This is the correct code:
const attach = this.db.prepare('ATTACH DATABASE ? AS temp;')
attach.run(databasePath)

Please read the very detailed documentation to learn how to use better-sqlite3.

Hi, How would I use transaction and call model layer function in my controller layer file?
My project use MVC architecture.
I have two model file: preset.model and task.model, and one controller file.
The preset schema only save name field, task schema has name and presetUid fields
I need to create preset first step and get presetUid, so that I can add the task.
preset.model.js
function add(preset) {
    const sql = `INSERT INTO preset (name) VALUES ($name)`
    const result = db.prepare(sql).run(preset.name)
    return result
}

task.model.js
function add(task) {
    const sql = `INSERT INTO preset (name, presetUid) VALUES ($name, $presetUid)`
    const param = {
        name: task.name,
        presetUid: task.presetUid
    }
    const result = db.prepare(sql).run(param)
    return result
}

In my controller.js file, I want to use preset.add and task.add function in model file
like this:
controller.js
import preset from './preset.model'
import task from './task.model'
import db from './db'

async function combo() {
    const data = { name: 'preset01'}
    try {
       await db.beginTransaction()   //  I want to start for transaction
       const preset = await preset.add(data)
       const task = {
            name: 'task01',
            presetUid: preset.lastInsertRowid
       }
       await task.add(task)
       await db.commit()  // I want to do commit
    } catch(error) {
        await db.rollback() // I want to rollback
    }
}

I know the documentation of better-sqlite does not have db.beginTransaction(), db.commit() and db.rollback() api. They are example to show what I want to do.
My problem is how can I do then I will get the same feature in my controller file.
Thank you.

@s7130457
function combo() {
    const data = { name: 'preset01'}
    try {
       db.exec("BEGIN TRANSACTION;");
       const preset = preset.add(data)
       const task = {
            name: 'task01',
            presetUid: preset.lastInsertRowid
       }
       task.add(task)
       db.exec("END TRANSACTION;");
    } catch(error) {
        db.exec("ROLLBACK TRANSACTION;");
    }
}

https://www.sqlite.org/lang_transaction.html
One more thing. There's no need for await in your functions. The library is synchronous.

@s7130457 @mygithubid1 so there is actually a transaction higher order function as part of the api https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#transactionfunction---function that was added in v5.
usage:
import preset from './preset.model'
import task from './task.model'
import db from './db'

function comboInserts() {
  const data = { name: 'preset01' }
  const presetReturn = preset.add(data)
  const taskData = { name: 'task01', presetUid: presetReturn.lastInsertRowId }
  task.add(taskData)
}
const comboTransaction = db.transaction(comboInserts)

// usage
comboTransaction()

I’m new to this so I hope you can help me..
I am trying to display all the datas I have under the table list in the names column but can’t make it work., this is my code:
row = db.prepare(SELECT names FROM list).all()
message.channel.send(row);

It displays:
[object Object]

the [object Object] repeats depending on how many entry is in the db, I just wanted it to display the all the names in the list table, I’m still a noob so hopefully you can help me.
Thank you.

@nierchi
Channel#send's first argument is content, which should be a string, however,
you provided an array of objects.
The default serialization/conversion for a string to an object.

Function Object:

stringify(function (){}) -> [object Function]

Array Object:

stringify([]) -> [object Array]

RegExp Object:

stringify(/x/) -> [object RegExp]

Date Object

stringify(new Date) -> [object Date]

Object Object

stringify({}) -> [object Object]

Several More!

In conclusion, you have to map the property or use for loop.

@chroventer ohh.. alright thank you for giving me that idea, I’ll tweak my code.
Thanks for the help 😊

Hi! Are there any performance benefits in preparing a statement once and then using it multiple times? E.g. i now have this:
function select(params){
    return db.prepare('...').run(params)
}

would this be more performant (or are there any drawbacks):
const statement = db.prepare('...');
function select(params){
   return statement.run(params);
}

Thanks in advance!

db.prepare returns a statement.
Part of this operation involves reaching out to the sqlite3 engine with a call to sqlite_prepare_v3 to compile the sql.
https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/api.md#class-statement

Hi! Are there any performance benefits in preparing a statement once and then using it multiple times? E.g. i now have this:
function select(params){
    return db.prepare('...').run(params)
}

would the following have better performance (or are there any drawbacks)?
const statement = db.prepare('...');
function select(params){
   return statement.run(params);
}

Thanks in advance!

Yes, if your query is relatively fast, reusing the prepared statement will result in a huge performance gain.

Hi,
I am new to this, so have few questions. How i can get the response back from the transaction which happen. For e,g.
function doMultipleTransaction(sqlQuery, sqlData) {   try {     log.info("SQl Query : ", sqlQuery);     log.info("SQl Data : ", sqlData);     log.info("Transaction Started");     const insert = db.prepare(sqlQuery);     const insertMany = db.transaction((sqlDataRows) => {       for (const sqlDataRow of sqlDataRows) {         insert.run(sqlDataRow);       }     });     return insertMany(sqlData);   } catch (err) {     // (transaction was forcefully rolled back) if any error while doing transaction     if (!db.inTransaction) throw err;   } }
From the above function, how can i get the response back of all the inserted records.
Or is there any better way of doing this.

you can return values from the transaction function. This will work:
function doMultipleTransaction(sqlQuery, sqlData) {
  try {
        log.info("SQl Query : ", sqlQuery);
        log.info("SQl Data : ", sqlData);
        log.info("Transaction Started");
        const insert = db.prepare(sqlQuery);
        const insertMany = db.transaction((sqlDataRows) => {
             return sqlDataRows.map(sqlDataRow => insert.run(sqlDataRow))
       });
       return insertMany(sqlData);
  } catch (err) {
    // (transaction was forcefully rolled back) if any error while doing transaction
    if (!db.inTransaction) throw err;
  }
}

I believe this is an undocumented feature

@manishrana87 I was about to reply exactly as @andykais did, but he beat me to it: Either collect the results into an array or into an object and return. .transaction() returns what it received.

Hi, I am having another question.
I have a array of item ["001", "002", "003"] .
These are primary key from a table "image". If I want to fetch the details from the "image" table.
In normal SQL editor, the query is,
Select * from image where image_id in ('001', '002', '003');`
How I can implement the same in terms of better-sqlite3.

@manishrana87, If your array always has three items, you can do this:
// First, open the database
const db = require('better-sqlite3')('my-database.db');

// Then, create a prepared statement
const statement = db.prepare("Select * from image where image_id in (?, ?, ?)");

// Lastly, run the query to get the results
const results = statement.all(["001", "002", "003"]);

However, if your array can have any number of items, you should do this:
// Same as before
const db = require('better-sqlite3')('my-database.db');

// This time, the statement only fetches a single item
const statement = db.prepare("Select * from image where image_id = ?");

// Run the query once for each item in the array
const results = array.map(item => statement.get(item));

@JoshuaWise, If I know I am working with a single nodejs process accessing my sqlite database, do I need to put a transaction around something like this:
const db = require('better-sqlite3')('my-database.db')

const selectStmt = db.prepare('SELECT * FROM cache WHERE cacheKey = ?')
const insertStmt = db.prepare('INSERT INTO cache (data, cacheKey) VALUES (?, ?)')

const ee = new EventEmitter()
ee.on('event', data => {
  // I want the select then insert to happen transactionally
  const cacheKey = JSON.stringify(data)
  const row = selectStmt.get(cacheKey)
  if (row === undefined) insertStmt.run(data, cacheKey)
})

// imagine these events are coming in asynchronously at any time
ee.emit('event', {some:'data'})
ee.emit('event', {some:'moredata'})

side note: I specifically cannot use a unique index here because sometimes I will insert into the database and not want the inserts to be unique, partial indexes will not work here because when I want to use the cache, I may access older rows which were created when the cache was not active.

@andykais Hi there. Why should your cache should support duplicate keys?

@andykais Since your SQL statements are executed synchronously (within the same event-loop tick), you don't need to worry about other events happening at the same time (assuming no other thread or process is accessing the same database, as you mentioned).

Why should your cache should support duplicate keys?

@mygithubid1 its a bit of a weird use case. This table servers both as a cache and storage for request/responses. Sometimes I want to use the cache (e.g. if a request has already been made with those parameters, grab the response from the database), and sometimes I do not want to use the cache (e.g. I know hitting the same endpoint will return different data each time, so I just want to store the responses in the database).
I dont want to derail this thread with more detailed explanations though, so lets leave it at that.

Hi,
My INTEGERS passed into db.prepare().run() are being cast/translated to REALs when executed.
I have a messages table (id INTEGER, json TEXT) that I want to update to show when a user has an unread or read message.
The json text/object is v. simple

id
json

1
'{"id": 1, "isRead": 0, ......}'

2
'{"id": 2, "isRead": 1, ......}'

where isRead is a 0 or 1 flag.
To update the isRead property within the json field, I pass a simple object containing only integers
msgObj = {
  isRead: 1,
  id: 1
}

But when I run this
 db.prepare(`
    UPDATE messages
    SET json = json_set(json, '$.isRead', :isRead)
    WHERE id = :id
  `).run({
    isRead: msgObj.isRead,
    id: msgObj.id
  })

isRead becomes {..."isRead": 1.0, ...} within the json text field.
I turned on {verbose: console.log} in my db require and the console shows me that the generated SQL is
    UPDATE messages
    SET json = json_set(json, '$.isRead', 1.0)
    WHERE id = 1.0

The id still identifies the correct row, as the UPDATE works, so the id field in the WHERE clause must be equating 1.0 with the INTEGER id of 1 in the table.
Is this normal/correct behaviour, or am I missing something?

Apologies if this seems straightforward but how do I create a table with a dynamic name?
Originally I thought I could do
const stmt= db.prepare(`CREATE TABLE ${MY_CUSTOM_NAME} (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    some_property TEXT NOT NULL
)`);

const i = stmt.run();

But that gives me the following error, assuming MY_CUSTOM_NAME was passed in as '2'
SqliteError {message: "near "2": syntax error", stack: "SqliteError: near "2": syntax error↵    at VueComp…ents/NacPage.vue?vue&type=script&lang=js&:165:10)", code: "SQLITE_ERROR", __ob__: Observer}
code: "SQLITE_ERROR"
message: "near "2": syntax error"
stack: "SqliteError: near "2": syntax error↵    at VueComponent._callee$ (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/index.js?!./src/renderer/components/NacPage.vue?vue&type=script&lang=js&:130:35)↵    at tryCatch (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:62:40)↵    at Generator.invoke [as _invoke] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:296:22)↵    at Generator.prototype.<computed> [as next] (webpack-internal:///./node_modules/regenerator-runtime/runtime.js:114:21)↵    at step (webpack-internal:///./node_modules/babel-runtime/helpers/asyncToGenerator.js:17:30)↵    at eval (webpack-internal:///./node_modules/babel-runtime/helpers/asyncToGenerator.js:35:14)↵    at new Promise (<anonymous>)↵    at new F (webpack-internal:///./node_modules/core-js/library/modules/_export.js:36:28)↵    at eval (webpack-internal:///./node_modules/babel-runtime/helpers/asyncToGenerator.js:14:12)↵    at VueComponent.addDrug (webpack-internal:///./node_modules/babel-loader/lib/index.js!./node_modules/vue-loader/lib/index.js?!./src/renderer/components/NacPage.vue?vue&type=script&lang=js&:165:10)"
__ob__: Observer {value: SqliteError, dep: Dep, vmCount: 0}
__proto__: Error

@simeon9696
According to the docs at https://www.sqlite.org/lang_createtable.html, , the only names forbidden are those that begin with sqlite_
However, if a table name contains a space or starts with a number, it needs to be in double quotes https://www.sqlite.org/lang_keywords.html, so
const stmt= db.prepare(`CREATE TABLE "${MY_CUSTOM_NAME}" (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    some_property TEXT NOT NULL
)`);

should work.

@DefCheese works like a charm! Thanks for pointing out the documentation for me!

So I'm having a bit of difficulty understanding how the INSERT statement works with parameter binding. From the docs:
// The following are equivalent.
const stmt = db.prepare('INSERT INTO people VALUES (@firstName, @lastName, @age)');
stmt.run({
  firstName: 'John',
  lastName: 'Smith',
  age: 45
});

This means that @firstName = John etc but does firstName correspond to a column in the table? If the first column was named cities and the second towns and the above statement was run. Would the entry in cities be John and towns be Smith because that's the order of the data in the INSERT statement?
TL:DR: Are bindings in INSERT statements bound to column names in a table or the order in which the columns appear in the table. I ask because rn I'm inserting data with bound parameters and the object has the keys and values mapped correctly but some of the column data is swapped around when it comes out.

@simeon9696
INSERT  can be used on specific column names in your table, or all of them
Assuming your table is
CREATE TABLE locations (
  street TEXT,
  town TEXT,
  zip TEXT
);

then INSERT can be used on all columns like this:
const stmt = db.prepare('INSERT INTO locations VALUES (@a, @b, @c)');
stmt.run({
  a: 'High Street',
  b: 'BigTown',
  c: '12345'
});

...and the values would be inserted into the columns in the order they were defined in the CREATE TABLE above (a goes into street, b to town, etc.)
However, you can also specify the order yourself and even omit columns) using
const stmt = db.prepare('INSERT INTO locations (zip, town) VALUES (@a, @b)');
stmt.run({
  a: '12345',
  b: 'BigTown'
});

street would then be NULL for this inserted row.
The bind names you use (a, b, c) don't relate directly to the column names, just the order you use them in the SQL statement.
So
const stmt = db.prepare('INSERT INTO locations (zip, town) VALUES (@b, @a)');
stmt.run({
  a: 'BigTown',
  b: '12345'
});

will also work fine. Obviously, using meaningful bind variable names is preferred over a, b, c, etc. :)

Is it possible to pass in a table name as a parameter in a transaction?
//From the docs
const insert = db.prepare('INSERT INTO cats (name, age) VALUES (@name, @age)');

const insertMany = db.transaction((cats) => {
  for (const cat of cats) insert.run(cat);
});

insertMany([
  { name: 'Joey', age: 2 },
  { name: 'Sally', age: 4 },
  { name: 'Junior', age: 1 },
]);

But lets say each cat had its own table so instead of saying
const insert = db.prepare('INSERT INTO cats (name, age) VALUES (@name, @age)');
You'd write
const insert = db.prepare('INSERT INTO "${cat_name}"(name, age) VALUES (@name, @age)');
I was thinking of putting it inside the function itself but that just seems inefficient. I did see in the docs Any arguments passed to the transaction function will be forwarded to the wrapped function but I don't know how to pass the arguments passed into the function into the prepared statement.

I have one query.
My create table statement is like this.
CREATE TABLE IF NOT EXISTS cron_job_header (id INTEGER PRIMARY KEY AUTOINCREMENT, cronExpression TEXT, scheduleUploadStatus TEXT, scheduleCreatedTime TEXT)
Here id is a integer and should be autoincremented.
What will be the insert statement for this table having below data.
{ cronExpression: 'At 06:30 PM, on day 15 of the month, only in September', scheduleUploadStatus: 'Pending', scheduleCreatedTime: 2020-10-21T10:54:51.001Z }
Because when I am trying to insert this record in a table, it is giving me below error.
Error while creating a record  TypeError: SQLite3 can only bind numbers, strings, Buffers, and null.
Can someone help me with this.

[ ] [_**a**_](

[ ] 1. url

)

[ ] [_**a**_](

[ ] 1. url

)

Using a loop is quite efficient, @dimitry-ishenko.

This is not correct, @JoshuaWise .  The larger the bulk insert, the more times you avoid updating the various indices.  If you bulk insert 100,000 rows on a table with 3 indices, you have avoided 299,997 index updates (even with the WAL, this takes a noticable amount of time.)
@dimitry-ishenko - the surrounding library does not make this choice.  What you're asking is part of the query language.
The answer is "yes, SQLite gained bulk inserts in 3.7.11."

Hey i was using the ? character
db.prepare('CREATE TABLE ? (?)')

But when i was running the code it saysme this error

I cant use the ? character? And if i cant, why?

Im writing a good amount of code that requires re-running inserts on unique rows. I have essentially two options at my disposal. Either run an insert, catch the error and run a select, or I add an ON CONFLICT clause, and perform an update so that I can use the RETURNING clause. Examples below:
Option 1
db.exec(`CREATE TABLE tag (
           id INTEGER PRIMARY KEY NOT NULL,
           name TEXT UNIQUE NOT NULL,
           created_at DATETIME NOT NULL);`)
const insert_stmt = db.prepare('INSERT INTO tag (name, created_at) VALUES (?, ?)')
const select_stmt = db.prepare('SELECT id FROM tag WHERE name = ?')

function create_tag(name) {
  try {
    return insert_stmt.run(name, new Date().toString()).lastInsertRowid
  } catch (e) {
    // also, no good way to distinguish a 'unique constraint' sqlite error from others
    return select_stmt.get(name).id
  }
}

create_tag('red') // 1
create_tag('red') // 1

Option 2
db.exec(`CREATE TABLE tag (
           id INTEGER PRIMARY KEY NOT NULL,
           name TEXT UNIQUE NOT NULL,
           created_at DATETIME NOT NULL);`)
const insert_stmt = db.prepare(`INSERT INTO tag (name, created_at) VALUES (?, ?)
                                ON CONFLICT DO UPDATE SET name = name
                                RETURNING id`)

function create_tag(name: string) {
  const row = insert_stmt_2.get(name, new Date().toString())
  return row.id
}

console.log(create_tag('green')) // 2
console.log(create_tag('green')) // 2

The prior is error prone since at best I can capture all SqliteErrors, but the latter does two write operations (I think) which feels bad, and uses RETURNING + .get on inserts, which I am unsure of, but am afraid will have performance implications.
Is this the best way to get the id of conflicting rows?

Is this the best way to get the id of conflicting rows?

the best way is to prevent them, rather than to make them then clean them up
you should either insert where not exists or insert or replace into

insert where not exists wouldnt give me back the id of the row that already exists. The point of doing it this way is to return the id for some data thats unique with a single query.
How is insert or replace into different than insert .. on conflict do update?

one's sql, the other is a nonstandard extension
one has significantly more overhead than the other
one performs the write and then undoes it, the other prevents the write in
the first place in many cases
one has handler overhead, the other doesn't
one uses common things, the other uses obscure things that most people
don't know the rules about (including you)
the reason i didn't return the id is that there are several good ways to do
that.  you could just put select on the query in the obvious way, but
generally, it's better to do the inserts and then do the select afterwards,
because it's faster, it gets you a point answer without a transaction, it
accommodates other online clients, and because it lets you gather just the
relevant columns and omit ones you added for thoroughness
On Tue, Aug 24, 2021 at 7:35 AM Andrew Kaiser @.***>
wrote:

insert where not exists wouldnt give me back the id of the row that
already exists. The point of doing it this way is to return the id for some
data thats unique with a single query.
How is insert or replace into different than insert .. on conflict do
update?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/JoshuaWise/better-sqlite3/issues/125#issuecomment-904699018,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/AAAS5KQOC3CR4ZUTDA7NZ6TT6OU4PANCNFSM4E6NEIMA
.

one has significantly more overhead than the other

what is the overhead? I just ran a benchmark and insert or replace vs on conflict do update are nearly identical:
insert_or_select avg speed: 0.065ms over 1000 runs
upsert avg speed: 0.583ms over 1000 runs
insert_or_replace avg speed: 0.560ms over 1000 runs

benchmark code
import { performance } from 'perf_hooks'
import Sqlite from 'better-sqlite3'

const db = new Sqlite('sqlite.db')

const BENCHMARK_RUNS = 1000
function benchmark(name:string,func:() => any) {
  let time_sum = 0
  for (let i = 0; i < BENCHMARK_RUNS; i++) {
    const start = performance.now()
    func()
    const end = performance.now()
    time_sum += (end - start)
  }
  const average = time_sum/BENCHMARK_RUNS
  console.log(`${name} avg speed: ${average.toFixed(3)}ms over ${BENCHMARK_RUNS} runs`)
}

db.exec(`DROP TABLE IF EXISTS tag;`)
db.exec(`CREATE TABLE tag (
           id INTEGER PRIMARY KEY NOT NULL,
           name TEXT UNIQUE NOT NULL,
           created_at DATETIME NOT NULL);`)
const insert_stmt = db.prepare('INSERT INTO tag (name, created_at) VALUES (?, ?)')
const select_stmt = db.prepare('SELECT id FROM tag WHERE name = ?')

function insert_or_select(name: string) {
  try {
    return insert_stmt.run(name, new Date().toString()).lastInsertRowid
  } catch (e) {
    if (e instanceof Sqlite.SqliteError) return select_stmt.get(name).id
    else throw e
  }
}

const upsert_stmt = db.prepare(`INSERT INTO tag (name, created_at) VALUES (?, ?)
                                ON CONFLICT DO UPDATE SET name = name
                                RETURNING id`)
function upsert(name: string) {
  const row = upsert_stmt.get(name, new Date().toString())
  return row.id
}

const insert_or_replace_stmt = db.prepare(`INSERT OR REPLACE INTO tag (name, created_at) VALUES (?, ?)`)
function insert_or_replace(name: string) {
  const row = insert_or_replace_stmt.run(name, new Date().toString())
  return row.lastInsertRowid
}

benchmark('insert_or_select', () => insert_or_select('red'))
benchmark('upsert', () => upsert('green'))
benchmark('insert_or_replace', () => insert_or_replace('green'))

generally, it's better to do the inserts and then do the select afterwards,
because it's faster

this does appear to be the case. It complicates my code slightly, but this does appear to be the faster solution by far
Its also worth pointing out that insert or replace is not going to be equivilant to an upsert even outside of the internals of sqlite sql parsing. on conflict do update will update a row, but insert or replace will delete the old row and create a new row. This means if you try doing an insert or replace on a row that is referenced by another table, youre going to break your foreign keys.

ok good luck

Is there a recommended way or only one way (like this) to prepare one-off statements?
I don't know enough C or C++ to find out how prepare() is implemented in better-sqlite3, but my guess is that those are only finalized() before closing database connection. What if I don't want to reopen the database just to finalize() them?
I'm asking this because exec() is highly discouraged due to injection risk, but I don't see another simple way to execute dynamically generated SQLs (they are complicated in my case because of relational division) other than the above. What's the rough performance difference between exec() and prepare() since "All SQL must be converted into a prepared statement before it can be run" from SQLite doc?

Is there a way for better-sqlite3 to evaluate json when using json_object?
In this example:
SELECT m.*, json_group_array(json_object('name', p.name, 'rating', p.rating, 'team', t.team)) teams FROM matches m LEFT JOIN teams t ON m.id = t.match LEFT JOIN players p ON p.id = t.player  ORDER BY date ASC

When I run .all() on this statement I get an array of match objects, but each teams is a JSON string that I need to parse.

Hi,
I want to filter records using in(). How can I do that with named parameters?
db.prepare('select * from test_table where string_column in ($values)').all({ values: [ 'a', 'b' ] })

should end up as:
select * from test_table where string_column in ('a', 'b')

I know that I can kind of do that by dynamically generating the SQL string before passing it to .prepare() but that's probably a little unreadable especially when in combination with other, 'normal' parameters, also because I can't use named parameters.
const asValues = [ 'a', 'b' ]
const sPlaceholders = asValues.map(sV => '?').join(', ');
const sSql = `select * from test_table where first_col = ? and other_col in (${sPlaceholders})`;

db.prepare(sSql).all('value_first_col', asValues);

Thanks.
PS.: As far as I understand, filling in the parameter values in the SQL statement is a thing SQLite itself does and not better-sqlite3, right? So maybe I'm wrong here.

I apologize if I missed this somewhere, but unfortunately the type of statement I'm after contains a field name in between its key words which makes it hard to search for. Anyway, here's the background:
I have a database that contains two tables. The first table, library, contains the main data entries. The second table, tags, contains text tags that can be used to describe and group the contents of the library table. The primary key of the library table is the column, hash. The tags table relates its entries on the same field, hash, as a foreign key into the library table.
Here's the question:
I want to run this query:
select * from library where hash in (select hash from tags where text in ('new', 'test'));

In my Javascript it looks like this:
const tags = ['new', 'test']
const sql = 'select * from library where hash in (select hash from tags where text in (?));'
const results = db.prepare(sql).all(tags)

The code generates the error: RangeError: Too many parameter values were provided
I have also tried:
const tags = ['new', 'test']
const sql = 'select * from library where hash in (select hash from tags where text in (?));'
const results = db.prepare(sql).all(...tags)

This generates the same error: RangeError: Too many parameter values were provided
The stumper for me is that if my array only contains one value, then it works:
const tags = ['new']
const sql = 'select * from library where hash in (select hash from tags where text in (?));'
const results = db.prepare(sql).all(...tags)

How do I use better-sqlite3 for this kind of statement? Thanks!

You have two tags, you need two placeholders.
const tags = ['new', 'test']
const sql = 'select * from library where hash in (select hash from tags where text in (?, ?))'
const results = db.prepare(sql).all(tags)

If your tags are dynamic so you don't know in advance how many tags there will be you can dynamically generate the placeholders too.
const tags = ['new', 'test']
const placeholders = Array.from(tags).fill('?').join(', ')
const sql = `select * from library where hash in (select hash from tags where text in (${placeholders}))`
const results = db.prepare(sql).all(tags)

@elyobo  - dynamically generating queries is a severe security risk and needs to be left in 1990 with php.  please don't give that advice.  that's the most common cause of injections..
@driverjb - generally speaking sqlite does not support the parameter binding of arrays; there's nothing better-sqlite can do about that.  the typical approach is to create a temporary table, insert your arguments into that, and join against it instead.  it's a pain in the butt.  on the bright side, it's also typically faster, and unlike in, is fairly re-usable on those occasions that that matters.

Dynamically generating queries with use input yes; dynamically generating queries with safe placeholders to use with prepared statements is fine.

I have a general query. Is there any overhead in having many SQLite databases open at the same time?
I'm trying to understand if we should have a single DB or several smaller DBs (e.g 100s individual dbs).
We are currently having a single database and prefixing the tables with customer_id. But it'd be a lot easier if we could have a db per customer.

I have a general query. Is there any overhead in having many SQLite databases open at the same time?

A small, probably unimportant amount.  SQLite needs several hundred K of ram.

I'm trying to understand if we should have a single DB or several smaller DBs (e.g 100s individual dbs).

You almost certainly should have a single database.  This is not related to needs of the tool.  You can treat the single database like it's distinct; the converse is not true.  One will eventually need to be retooled; the other will not.

prefixing the tables with customer_id.

Use a single table with a defining column instead.

But it'd be a lot easier if we could have a db per customer.

You absolutely can.  You just shouldn't.  You will lose out on the ability to make any decisions across the set.

@danielepolencic The correct way of handling this would be to have a single database that has a table that contains your customers with the primary key of say, customer_id. Then all your other tables have a foreign key matching up to that customer_id so that a given customers data can be selected from the table. This allows a single table for each set of data instead of juggling what sounds like a nightmare scenario of tables all with different names that represent the same data sets for different customers.

Hi,
I wrote this code:
let statement = db.prepare(`SELECT COUNT(*) FROM main WHERE userId = ?`);     let row = statement.get(user.id);     console.log(row);
which returns { 'COUNT(*)': 1 }
I made it so I can check easier if a row with that userId already exist or not. But how would I check for the count since row.count(*) won't work?

I would change it to this:
function userExists(userId) {
  const statement = db.prepare(`SELECT 1) FROM main WHERE userId = ?`);
  const row = statement.get(user.id);
  return row !== undefined
}

const doTheyExist = userExists(user.id)

@Dezaku I would change it to this:
function userExists(userId) {
  const statement = db.prepare(`SELECT 1 FROM main WHERE userId = ?`);
  const row = statement.get(user.id);
  return row !== undefined
}

const doTheyExist = userExists(user.id)

Thats a way easier way, thank you!

That was the long version that makes it clear what's happening. You could shorten it to this:
function userExists(userId) {
  return db.prepare('SELECT 1 FROM main WHERE userId = ?').get(userId) !== undefined
}

const doTheyExist = userExists(user.id)

That was the long version that makes it clear what's happening. You could shorten it to this:
function userExists(userId) {
  return db.prepare('SELECT 1 FROM main WHERE userId = ?').get(userId) !== undefined
}

const doTheyExist = userExists(user.id)

Alright, thank you!

Hello guys, I'm currently trying to get the top 10 values of my "total" column. Somehow two errors occur and I can't seem to fix them. This is my code
const statement =
      db.prepare(`SELECT total FROM main ORDER BY total DESC LIMIT 10
    `);
const rows = statement.get(); // I also tried statement.all() but the same error occurs
      console.log(rows);

Since I also tried statement.all() I assume something is wrong with the statement itself but I didn't find any solution yet.
This is the error:
  Received one or more errors

  1 ExpectedValidationError > s.literal(V)
  |   Expected values to be equals
  |
  |   Expected:
  |   | null
  |
  |   Received:
  |   | ''

  2 ExpectedConstraintError > s.string.lengthGreaterThanOrEqual
  |   Invalid string length
  |
  |   Expected: expected.length >= 1
  |
  |   Received:
  |   | ''

Hello guys, I get two errors which I can't seem to fix. This is the code:
const userArray = [];
    const totalArray = [];

    function getUserIDs() {
      const stmt = db.prepare(
        `SELECT userid FROM Users ORDER BY total DESC LIMIT 10`
      );
      for (const row of stmt.iterate()) {
        userArray.push(row.userid);
      }
    }
    function getTotals() {
      const stmt = db.prepare(
        `SELECT total FROM Users ORDER BY total DESC LIMIT 10`
      );
      for (const row of stmt.iterate()) {
        totalArray.push(row.total ? row.total : "0");
      }
    }
    try {
      getUserIDs();
      getTotals();
    } catch (error) {
      console.log(error);
    }
console.log(userArray, totalArray);

And these are the errors:
CombinedError (2)
  Received one or more errors

  1 ExpectedValidationError > s.literal(V)
  |   Expected values to be equals
  |
  |   Expected:
  |   | null
  |
  |   Received:
  |   | ''

  2 ExpectedConstraintError > s.string.lengthGreaterThanOrEqual
  |   Invalid string length
  |
  |   Expected: expected.length >= 1
  |
  |   Received:
  |   | ''

    at UnionValidator.handle (C:\Development\Bots\v14\CakeBot\node_modules\@sapphire\shapeshift\dist\index.js:1085:23)
    at UnionValidator.parse (C:\Development\Bots\v14\CakeBot\node_modules\@sapphire\shapeshift\dist\index.js:142:88)
    at EmbedBuilder.setDescription (C:\Development\Bots\v14\CakeBot\node_modules\@discordjs\builders\dist\index.js:231:26)
    at Object.execute (C:\Development\Bots\v14\CakeBot\src\commands\currencySystem\leaderboard.js:44:8)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Object.execute (C:\Development\Bots\v14\CakeBot\src\events\client\interactionCreate.js:11:9)
node:events:505
      throw er; // Unhandled 'error' event
      ^

userArray and totalArray both still get logged into the console normally and the output it shows is what it should be

repeatedly preparing the query is wasteful
const exists_q = db.prepare('select 1 from main where userid = ?'),
      userExists = userId => exists_q.get(userId) !== undefined;

Is there a way to wait for a database entry to appear?
Say my code looks like this:
events.on('someEvent', event => {
    db.prepare('INSERT INTO events (id, someValue) VALUES (?, ?)')
        .run(event.id, event.someValue);
});

events.on('otherEvent', event => {
    const previousEvent = db.prepare('SELECT * FROM events WHERE id = ?')
        .get(event.referenceId);
});

Now say that there's some code in someEvent that takes a bit of time to finish before inserting into the database. Is there some way to wait for event.referenceId to appear in the database, potentially with a timeout if it never does?

I'm uploading images to my node.js server and saving those in a table in my sqlite db. I'd like to stream that file upload straight to the table rather than reading the whole image in memory before doing the insert.
I saw that SQLite should support this via blob_write and better-sqlite3 appears to support blob_write, however, I'm not certain how to make use of this.
What I have is a data type of AsyncIterable<Uint8Array>. I'm not sure how to convert this to whatever better-sqlite3 needs for my insert:
imageDb
	.prepare(
		/* sql */ `
		INSERT INTO "Images"
			(updatedAt, contentType, blob)
			VALUES (@updatedAt, @contentType, @blob)
	`,
	)
	.run({updatedAt: new Date().toISOString(), contentType, blob: data}) // <-- data is the Uint8Array in an AsyncIterable

Tips are appreciated. Thanks!

Hello, I am inserting some values into a table:
const sqlite3 = require('better-sqlite3');

const db = sqlite3(":memory:");
db.pragma('journal_mode = WAL');

db.exec("CREATE TABLE mytable (id INTEGER PRIMARY KEY AUTOINCREMENT, value TEXT NOT NULL)")

const sql =`
  INSERT INTO mytable (value) VALUES (:value)
`;

const stmt = db.prepare(sql);
stmt.run({'value'=>'some text'});

// Get the generated mytable.id here

How I can retrieve the inserted id?

@pc-magas - sqlite3 .run returns an object with two properties.  one is the count of changed rows; the other is the last insert id.
const stmt = db.prepare('INSERT INTO cats (name, age) VALUES (?, ?)');
const info = stmt.run('Joey', 2);

console.log(info.changes); // => 1
console.log(info.lastInsertId); // => if first cat, 1; otherwise higher

SELECT     COUNT(progress_id) total_done,     SUM(session_length) FROM     progress_table WHERE     strftime("%Y-%m-%d",time_stamp,"localtime") > (SELECT DATE("now", "-7 day","localtime"))
What I am doing wrong here, In my "DB Browser for SQLITE", this query does not throw any error, How ever in better-sqlite, node is throwing
SqliteError: no such column: now
Is there a different way of writing this query for better-sqlite to work?.

Use single quotes for strings and you'll be fine.
SQL strings are generally single quoted, double quotes generally used for quoting identifiers e.g. if you have a column name with unsafe chars like a space in them. I've noticed that SQLite is inconsistently forgiving in this regard (there's presumably a pattern to it, but I haven't looked - I just use single quotes by habit anyway, but a colleague ran into this in a subtle and confusing bug).

Use single quotes for strings and you'll be fine.
SQL strings are generally single quoted, double quotes generally used for quoting identifiers e.g. if you have a column name with unsafe chars like a space in them. I've noticed that SQLite is inconsistently forgiving in this regard (there's presumably a pattern to it, but I haven't looked - I just use single quotes by habit anyway, but a colleague ran into this in a subtle and confusing bug).

Thank you so much for your quick, it worked.

Hi there, I wonder how I can do operations across databases. Like,
-- Analysis DB
CREATE TABLE Reports ( date: bigint, ruleID: int)
-- Basic DB
CREATE TABLE Rules (ruleID: int, desc: text)

How I can join these two tables on ruleID across databases? I don't want to fetch data from these dbs separately and do 'join like' operations in js (forEach & Map).

Conventional usage with Express?
Most other DBs rely on connection pools that handle reconnects for us (allowing concurrent reads as well).
Hovewer, for SQLite it's not recommended to use pooling:

I personally wouldn't use better-sqlite-pool. It's possible there's something I'm missing, but it seems like an anti-pattern. The best way to use better-sqlite3 in a single-threaded environment such as Node.js is to only use a single connection for the entire application, and to only run transactions synchronously (within a single event-loop tick).
https://github.com/WiseLibs/better-sqlite3/issues/234

Then the question arises: how to handle DB disconnects?
According to the docs new Database() creates a new connection. If I just reconnect per HTTP request, I can't benefit from prepare statements, not to say it's likely a waste of CPU to reconnect so often...
But, if I connect once, without a connection pool, the connection will eventually be lost and the app will crash.
Surprisingly, I couldn't find more information about reconnects and proper connection management within a web server setup. So asking it here 🤔

@ivan-kleshnin , sqlite is not a server client model.  it's a flat file parser local library.  there aren't many realistic situations under which it would "disconnect."

@JoshuaWise If you could help with the above that would be awesome. This is a bit out of the depths of mostly everyone I know that uses sqlite ;)
What I feel I'm looking for would look like :
  filter2(predicate) {
    this.#db.aggregate('filter', {
      start: [],
      step: (accumulator, [value, key]) => {
        const parsed = JSON.parse(currentValue);
        if (predicate(parsed)) {
          accumulator.push(parsed);
        }
        return accumulator;
      },
      result: (accumulator) => JSON.stringify(accumulator),
    });
    const results = this.#db
      .prepare(`SELECT filter(value, key) FROM mytable`)
      .pluck()
      .get();
    return JSON.parse(results);
  }

this gives me an error about the wrong number of arguments. Arrays and objects don't work either. I Really hope there's a way :(

@JoshuaWise If you could help with the above that would be awesome. This is a bit out of the depths of mostly everyone I know that uses sqlite ;)
What I feel I'm looking for would look like :
  filter2(predicate) {
    this.#db.aggregate('filter', {
      start: [],
      step: (accumulator, [value, key]) => {
        const parsed = JSON.parse(value);
        if (predicate(parsed, key)) {
          accumulator.push(parsed);
        }
        return accumulator;
      },
      result: (accumulator) => JSON.stringify(accumulator),
    });
    const results = this.#db
      .prepare(`SELECT filter(value, key) FROM mytable`)
      .pluck()
      .get();
    return JSON.parse(results);
  }

this gives me an error about the wrong number of arguments. Arrays and objects don't work either. I Really hope there's a way :(

You almost got it, just get rid of the array brackets:
db.aggregate('filter', {
  start: [],
  step: (accumulator, value, key) => {
    const parsed = JSON.parse(value);
    if (predicate(parsed, key)) {
      accumulator.push(parsed);
    }
    return accumulator;
  },
  result: (accumulator) => JSON.stringify(accumulator),
});

const results = db
  .prepare(`SELECT filter(value, key) FROM mytable`)
  .pluck()
  .get();

return JSON.parse(results);

@JoshuaWise This is awesome! I guess it really was a question of matching parameter counts between the functions. Might I suggest this as an example in the docs somewhere? I even went and looked at your tests which all look at a single row, so I was wondering about the possibility, even. But now I know, and Enmap will be better for it, so thank you!

How can I find where SQLite stores data when using an in-memory database (:memory:)?
The memory consumption of a Node.js server process using an SQLite in-memory database decreased from 1.5 GB to 50 MB in Task Manager, while the SQLite database still contains 1 GB of data. The database size was found using this query: SELECT (page_count - freelist_count) * page_size AS size FROM pragma_page_count(), pragma_freelist_count(), pragma_page_size().

authors: 5t4rdu5t DeepJoyPo DefCheese Dezaku JSmental JYone3A JefStat JoshuaWise JustIzumi KaustubhMogha11 Nikumarekko StoneCypher TheColorman VyrekXD andrewkolos andykais arne bog-sb bombard-kb chroventer danielepolencic dimitry-ishenko driverjb elyobo eslachance fakob ivan-kleshnin janith-dev kentcdodds manishrana87 mceachen memoz mygithubid1 nierchi pc-magas s7130457 shadeofgod simeon9696 vurdeljica


text:
NPE on auto-test done by Google

Hello,
When I publish my app, Google starts auto-test on various devices. Since two releases Google give a NPE with this stack trace:
java.lang.NullPointerException: Attempt to invoke interface method 'android.os.Bundle com.android.vending.billing.IInAppBillingService.getBuyIntent(int, java.lang.String, java.lang.String, java.lang.String, java.lang.String)' on a null object reference
 	at com.smartmobilesoftware.util.IabHelper.launchPurchaseFlow(IabHelper.java:386)
 	at com.smartmobilesoftware.util.IabHelper.launchPurchaseFlow(IabHelper.java:338)
 	at jp.wizcorp.wizpurchase.WizPurchase.buy(WizPurchase.java:416)
 	at jp.wizcorp.wizpurchase.WizPurchase.access$200(WizPurchase.java:40)
 	at jp.wizcorp.wizpurchase.WizPurchase$4.run(WizPurchase.java:296)
 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
 	at java.lang.Thread.run(Thread.java:818)

In a physical use, no exception...
Google told me that the tested device is Galaxy S6 under Android 5.1. Others 5.1 devices pass all the tests.

Thanks for pointing out this issue. 👍
I'll try to have a look at this this week.

@CyrilleGuimezanes By the way, do you have any JS code to share that could help reproduce/understand this issue?

Actually it's a really simple use of your plugin and in a normal use (when I use my phone under android 6.0), it not crash
Here is the logcat attached to Google bug report if that can help:
logcat.txt

Hello,
Thanks for the logcat file! I tried to trace back your error but I couldn't find why you have this exception as everything seems to be properly initialized.
As I have no way to reproduce it currently, would you be able to make a new build with debug logs activated in IabHelper and attach the resulting logs?
This can be done either by:

directly replacing IabHelper.java l.74 by: boolean mDebugLog = true;
or adding in WizPurchase.java l.359 this line: mHelper.enableDebugLogging(true);

authors: CyrilleGuimezanes jrouault

repo: Wizcorp/cordova-plugin-wizpurchase


text:
BUG: Status page does not load.

its not loading

Flxed Uploaded Files

repo: Wizqdev/Status-Page-Api


text:
🛑 万界规划局共享资源库 (Wjghj Project Static Database) is down

In ed8dcc5, 万界规划局共享资源库 (Wjghj Project Static Database) (https://common.wjghj.cn) was down:

HTTP code: 0
Response time: 0 ms

Resolved: 万界规划局共享资源库 (Wjghj Project Static Database) is back up in 4c8bbbb.

repo: Wjghj-Project/status


text:
Package test

Hi @LogSkele , I wanted to do a test package before doing it on authenticlick. I have already created a package but can't seem to import it after downloading it.

You have to do it in a IDE with a terminal like VS Code?

Then in the same directory as dist,
python3 -m twine upload dist/*

If you are on windows.

Bro, I uploaded the package already. Just couldn't download it

:>

authors: LogSkele Wjplatformer

repo: Wjplatformer/package-py-test


text:
Request for export with Flat Shading

I tried to export with surface shader in maya as it is the only flat shader available but the textures didnt get exported with that material. Is it possible to convert the lambert shader automatically into Flat shader when exporting as gltf?

i need it to get exported as this material meshbasicmaterial. instead it gets exported as meshstandardmaterial as i checked by importing into threejs. Please let me know how to export as meshbasic material from maya as it a flat shader

I'm not sure I follow you. Maya doesn't really have a "flat shader" as far as I know.
You just set the vertex normals to be the face normals
Then you assign a Lambert or our PBR shader, apply textures, and export to GLTF (I have several flat shaded simple models in this repository).
Regarding ThreeJS, I don't know what rules it applies to convert the GLTF material to its internal shaders, maybe others could help here?

@Ziriax I mean when exported as gltf from maya instead of using meshstandardshader is it possible to force meshbasicshader as this is the flat shader in threejs.

I'm not sure I follow you. Maya doesn't really have a "flat shader" as far as I know.
You just set the vertex normals to be the face normals
Then you assign a Lambert or our PBR shader, apply textures, and export to GLTF (I have several flat shaded simple models in this repository).
Regarding ThreeJS, I don't know what rules it applies to convert the GLTF material to its internal shaders, maybe others could help here?

Thank you, how to convert vertex normal to face normal?

This tutorial might help, but Google "Maya set to face normals" will help too.
https://www.youtube.com/watch?v=0xB7nb0E448&t=11m

authors: Ziriax thickaris


text:
Recognize sanitize_hex_color as a sanitization function

WPCS should recognize sanitize_hex_color() as a sanitization function.

This was fixed in #781

authors: jrfnl paulschreiber


text:
Implementation Plan: Augment the catalog database with suitable Rekognition tags

Due date:

2024-07-05
Assigned reviewers

[ ] @sarayourfriend - for your thoughts and context around sensitive data and machine-generated labels
[ ] @stacimc - for your deeper knowledge of the batched update process and the catalog in general

Description

Fixes #4040
This is the last and final IP for the Rekognition data project! It might look a little daunting, but I've tried to add as much rational and explanation to the document as I can. Based on the timezones of the reviewers, if a synchronous session for discussing this IP would be helpful in accelerating any review, I'm sure we could make it happen!
Current round
This discussion is following the Openverse decision-making process. Information
about this process can be found
on the Openverse documentation site.
Requested reviewers or participants will be following this process. If you are
being asked to give input on a specific detail, you do not need to familiarise
yourself with the process and follow it.

This discussion is currently in the Decision round.
The deadline for review of this round is 2024-07-05

Thanks @sarayourfriend for your input! I'm interested in hearing @stacimc's thoughts on the raised points before I make any changes to the IP.

Taking a look at this today, @AetherUnbound! 👀

@AetherUnbound, I finally found the tag analysis I did in April of 2023! In this gist there is a list of all 2,595 unique tags in the Openverse Rekognition data, and counts for the number of times each tag occurs. The script I used is included as well.
https://gist.github.com/zackkrida/ecba17d8fc89d8e4d8aa78e5e19199c0

There's a ton of excellent discussion as part of this IP, thank you to everyone who added input to it 💖 I'm going to put this in draft while we clarify some steps at other pieces of the pipeline, namely #4455 and #4456. That will give us an indication of how we want to handle the Rekognition loading (and subsequently, the Clarifai filtering) going forward. I'll focus on those, then bring the outcomes of them back to this IP for revision!

@AetherUnbound @stacimc after Madison is back from WCEU, regardless of whether revisions are finished, I think it we could finish this discussion in the synchronous chat. Even if Madison is still working on revisions, we can chat and make sure we'll be ready to approve once Madison is finished with revisions. I wanted to propose that last week, but kept forgetting and thinking it would be okay to do this week, and remembered only too late that Madison is AFK this week for the conference.
Anyway, I think we can get this totally squared away pretty quickly with a synchronous chat, and avoid this dragging beyond the end of next week.

@stacimc @sarayourfriend I've gone over this IP and rewritten pieces that assumed we'd be removing data from the catalog to reflect our recently refined "data warehouse" approach based on #4465 and other discussions. I've also made some changes to the filtering approach for Clarifai and explicitly noted gendered terms that might come up in the "acceptable" demographics. I believe this should be ready for final decision - I'm going to leave it open for the next two weeks while I'm AFK so there's plenty of time to gather more feedback if necessary! Thanks so much for your input on this!

Thank you both!

authors: AetherUnbound sarayourfriend stacimc zackkrida

repo: WordPress/openverse


text:
Delete Absolute Orientation fields and Movement Manner field

AbsOriPalm, AbsOriFing, and MovMan can be deleted from the models & database, and also from the detail view, the search panel Phonology, the CSV export, field choices in Django, and .... any other place?

Ha, finally my refactoring pays off :D. Because of all kinds of changes I made months ago, this was just a matter of removing three strings from a number of lists. I removed it from:

The detail view
The search view
The CSV export (for which I discovered the headers were broken by all internationalization, so I fixed that as well in the process)
The field choices

But not yet from the underlying database and model, because it's much handier to do that while cleaning other fields as well, as described in #114

authors: Woseseltops ocrasborn

repo: Woseseltops/signbank


text:
[Feature] Add Firebase Crashlytics to the project

WIP

Please don't – not only does this feed data to Google (privacy issues), it's also proprietary code. If you need analytics in a FOSS app, why not use a FOSS analytics library? I've heard good things about Plausible Analytics and Swetrix, for example (but then, I'm no Android dev myself so I cannot really compare). And if it's just about crash reporting, ACRA should be fine (F-Droid uses that and, as far as I heard, the devs there are quite happy with it). All three (and others from the list) can be used in a privacy-friendly way – which cannot be said about Crashlytics.
That said: I was looking for the APK, but it seems you provide your app only via Google's walled garden (which us privacy folks rather avoid: e.g. my devices all run without the Google stuff and I get my apps from F-Droid). Would you consider providing the APK (e.g. attached to its corresponding release), or bring your app to F-Droid (Crashlytics would be a show-stopper for that, as F-Droid only accepts fully FOSS code)?

Hey Izzy! Tks for comment! I really appreciate you care about privaty issues of my application, I will look those other options of analytics libraries!
In my mind is very interesting provide my application to everyone can use but sorry this project is just for studies, and I don't have plans to provide the app into other app store.
How this project is 100% open source you can duplicate the code or fork in your github and generate your apk/abb version! Please feel free to do so!

I really appreciate you care about privaty issues of my application, I will look those other options of analytics libraries!

Wonderful!

I don't have plans to provide the app into other app store.

Just provide the APK, and it can be in my repo within 24h if there are no show-stoppers :smiley:

you can duplicate the code or fork in your github and generate your apk/abb version!

I'm no Android developer (just a "power user" maybe). So yes, I probably could run gradle to produce the APK, but I'd be lost adjusting the code :see_no_evil:

authors: IzzySoft Wottrich

repo: Wottrich/android-smart-checklist