├── .github
├── stale.yml
└── workflows
│ └── main.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── SECURITY.md
├── binaries
├── sqlite-linux-x64
├── sqlite-win32-ia32.exe
└── sqlite-win32-x64.exe
├── cjs
└── sqlite-electron.js
├── esm
└── sqlite-electron.mjs
├── example
├── LICENSE
├── index.html
├── index.js
├── package.json
└── preload.js
├── package-lock.json
├── package.json
├── scripts
├── dependencies.js
└── postinstall.js
├── sqlite-electron.d.ts
├── sqlite-electron.ts
└── sqlite.py
/.github/stale.yml:
--------------------------------------------------------------------------------
1 | # Number of days of inactivity before an issue becomes stale
2 | daysUntilStale: 15
3 | # Number of days of inactivity before a stale issue is closed
4 | daysUntilClose: 2
5 | # Issues with these labels will never be considered stale
6 | exemptLabels:
7 | - pinned
8 | - security
9 | # Label to use when marking an issue as stale
10 | staleLabel: stale
11 | # Comment to post when marking an issue as stale. Set to `false` to disable
12 | markComment: >
13 | This issue has been automatically marked as stale because it has not had
14 | recent activity. It will be closed if no further activity occurs. Thank you
15 | for your contributions.
16 | # Comment to post when closing a stale issue. Set to `false` to disable
17 | closeComment: false
18 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: Publish Package to npmjs
2 | on: workflow_dispatch
3 | jobs:
4 | build:
5 | runs-on: ubuntu-latest
6 | permissions:
7 | contents: read
8 | id-token: write
9 | steps:
10 | - uses: actions/checkout@v4
11 | - uses: actions/setup-node@v4
12 | with:
13 | node-version: '20.x'
14 | registry-url: 'https://registry.npmjs.org'
15 | - run: npm install -g npm
16 | - run: npm ci
17 | - run: npm publish --provenance
18 | env:
19 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
20 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Logs
2 | logs
3 | *.log
4 | npm-debug.log*
5 | yarn-debug.log*
6 | yarn-error.log*
7 | lerna-debug.log*
8 | .pnpm-debug.log*
9 |
10 | # Diagnostic reports (https://nodejs.org/api/report.html)
11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
12 |
13 | # Runtime data
14 | pids
15 | *.pid
16 | *.seed
17 | *.pid.lock
18 |
19 | # Directory for instrumented libs generated by jscoverage/JSCover
20 | lib-cov
21 |
22 | # Coverage directory used by tools like istanbul
23 | coverage
24 | *.lcov
25 |
26 | # nyc test coverage
27 | .nyc_output
28 |
29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
30 | .grunt
31 |
32 | # Bower dependency directory (https://bower.io/)
33 | bower_components
34 |
35 | # node-waf configuration
36 | .lock-wscript
37 |
38 | # Compiled binary addons (https://nodejs.org/api/addons.html)
39 | build/Release
40 |
41 | # Dependency directories
42 | node_modules/
43 | jspm_packages/
44 |
45 | # Snowpack dependency directory (https://snowpack.dev/)
46 | web_modules/
47 |
48 | # TypeScript cache
49 | *.tsbuildinfo
50 |
51 | # Optional npm cache directory
52 | .npm
53 |
54 | # Optional eslint cache
55 | .eslintcache
56 |
57 | # Microbundle cache
58 | .rpt2_cache/
59 | .rts2_cache_cjs/
60 | .rts2_cache_es/
61 | .rts2_cache_umd/
62 |
63 | # Optional REPL history
64 | .node_repl_history
65 |
66 | # Output of 'npm pack'
67 | *.tgz
68 |
69 | # Yarn Integrity file
70 | .yarn-integrity
71 |
72 | # dotenv environment variables file
73 | .env
74 | .env.test
75 | .env.production
76 |
77 | # parcel-bundler cache (https://parceljs.org/)
78 | .cache
79 | .parcel-cache
80 |
81 | # Next.js build output
82 | .next
83 | out
84 |
85 | # Nuxt.js build / generate output
86 | .nuxt
87 | dist
88 |
89 | # Gatsby files
90 | .cache/
91 | # Comment in the public line in if your project uses Gatsby and not Next.js
92 | # https://nextjs.org/blog/next-9-1#public-directory-support
93 | # public
94 |
95 | # vuepress build output
96 | .vuepress/dist
97 |
98 | # Serverless directories
99 | .serverless/
100 |
101 | # FuseBox cache
102 | .fusebox/
103 |
104 | # DynamoDB Local files
105 | .dynamodb/
106 |
107 | # TernJS port file
108 | .tern-port
109 |
110 | # Stores VSCode versions used for testing VSCode extensions
111 | .vscode-test
112 |
113 | # yarn v2
114 | .yarn/cache
115 | .yarn/unplugged
116 | .yarn/build-state.yml
117 | .yarn/install-state.gz
118 | .pnp.*
--------------------------------------------------------------------------------
/CODE_OF_CONDUCT.md:
--------------------------------------------------------------------------------
1 |
2 | # Contributor Covenant Code of Conduct
3 |
4 | ## Our Pledge
5 |
6 | We as members, contributors, and leaders pledge to make participation in our
7 | community a harassment-free experience for everyone, regardless of age, body
8 | size, visible or invisible disability, ethnicity, sex characteristics, gender
9 | identity and expression, level of experience, education, socio-economic status,
10 | nationality, personal appearance, race, caste, color, religion, or sexual identity
11 | and orientation.
12 |
13 | We pledge to act and interact in ways that contribute to an open, welcoming,
14 | diverse, inclusive, and healthy community.
15 |
16 | ## Our Standards
17 |
18 | Examples of behavior that contributes to a positive environment for our
19 | community include:
20 |
21 | * Demonstrating empathy and kindness toward other people
22 | * Being respectful of differing opinions, viewpoints, and experiences
23 | * Giving and gracefully accepting constructive feedback
24 | * Accepting responsibility and apologizing to those affected by our mistakes,
25 | and learning from the experience
26 | * Focusing on what is best not just for us as individuals, but for the
27 | overall community
28 |
29 | Examples of unacceptable behavior include:
30 |
31 | * The use of sexualized language or imagery, and sexual attention or
32 | advances of any kind
33 | * Trolling, insulting or derogatory comments, and personal or political attacks
34 | * Public or private harassment
35 | * Publishing others' private information, such as a physical or email
36 | address, without their explicit permission
37 | * Other conduct which could reasonably be considered inappropriate in a
38 | professional setting
39 |
40 | ## Enforcement Responsibilities
41 |
42 | Community leaders are responsible for clarifying and enforcing our standards of
43 | acceptable behavior and will take appropriate and fair corrective action in
44 | response to any behavior that they deem inappropriate, threatening, offensive,
45 | or harmful.
46 |
47 | Community leaders have the right and responsibility to remove, edit, or reject
48 | comments, commits, code, wiki edits, issues, and other contributions that are
49 | not aligned to this Code of Conduct, and will communicate reasons for moderation
50 | decisions when appropriate.
51 |
52 | ## Scope
53 |
54 | This Code of Conduct applies within all community spaces, and also applies when
55 | an individual is officially representing the community in public spaces.
56 | Examples of representing our community include using an official e-mail address,
57 | posting via an official social media account, or acting as an appointed
58 | representative at an online or offline event.
59 |
60 | ## Enforcement
61 |
62 | Instances of abusive, harassing, or otherwise unacceptable behavior may be
63 | reported to the community leaders responsible for enforcement at
64 | tahaar5321@gmail.com .
65 |
66 | All complaints will be reviewed and investigated promptly and fairly.
67 |
68 | All community leaders are obligated to respect the privacy and security of the
69 | reporter of any incident.
70 |
71 | ## Enforcement Guidelines
72 |
73 | Community leaders will follow these Community Impact Guidelines in determining
74 | the consequences for any action they deem in violation of this Code of Conduct:
75 |
76 | ### 1. Correction
77 |
78 | **Community Impact**: Use of inappropriate language or other behavior deemed
79 | unprofessional or unwelcome in the community.
80 |
81 | **Consequence**: A private, written warning from community leaders, providing
82 | clarity around the nature of the violation and an explanation of why the
83 | behavior was inappropriate. A public apology may be requested.
84 |
85 | ### 2. Warning
86 |
87 | **Community Impact**: A violation through a single incident or series
88 | of actions.
89 |
90 | **Consequence**: A warning with consequences for continued behavior. No
91 | interaction with the people involved, including unsolicited interaction with
92 | those enforcing the Code of Conduct, for a specified period of time. This
93 | includes avoiding interactions in community spaces as well as external channels
94 | like social media. Violating these terms may lead to a temporary or
95 | permanent ban.
96 |
97 | ### 3. Temporary Ban
98 |
99 | **Community Impact**: A serious violation of community standards, including
100 | sustained inappropriate behavior.
101 |
102 | **Consequence**: A temporary ban from any sort of interaction or public
103 | communication with the community for a specified period of time. No public or
104 | private interaction with the people involved, including unsolicited interaction
105 | with those enforcing the Code of Conduct, is allowed during this period.
106 | Violating these terms may lead to a permanent ban.
107 |
108 | ### 4. Permanent Ban
109 |
110 | **Community Impact**: Demonstrating a pattern of violation of community
111 | standards, including sustained inappropriate behavior, harassment of an
112 | individual, or aggression toward or disparagement of classes of individuals.
113 |
114 | **Consequence**: A permanent ban from any sort of public interaction within
115 | the community.
116 |
117 | ## Attribution
118 |
119 | This Code of Conduct is adapted from the [Contributor Covenant][homepage],
120 | version 2.1, available at
121 | [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
122 |
123 | Community Impact Guidelines were inspired by
124 | [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
125 |
126 | For answers to common questions about this code of conduct, see the FAQ at
127 | [https://www.contributor-covenant.org/faq][FAQ]. Translations are available
128 | at [https://www.contributor-covenant.org/translations][translations].
129 |
130 | [homepage]: https://www.contributor-covenant.org
131 | [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
132 | [Mozilla CoC]: https://github.com/mozilla/diversity
133 | [FAQ]: https://www.contributor-covenant.org/faq
134 | [translations]: https://www.contributor-covenant.org/translations
135 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing to sqlite-electron
2 |
3 | Secweb welcomes contributors! This guide should help you submit issues and pull requests.
4 |
5 | ## Got a question, problem, or feature request?
6 |
7 | The documentation is a good place to start.
8 |
9 | Feel free to [add an issue](https://github.com/tmotagam/sqlite-electron/issues) if those don't help!
10 |
11 | ## Want to submit a change?
12 |
13 | If you're not sure whether your change will be welcomed, [add an issue](https://github.com/tmotagam/sqlite-electron/issues) to ask.
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | sqlite-electron module for electron and nodejs
635 | Copyright (C) 2020-2025 Motagamwala Taha Arif Ali
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | sqlite-electron Copyright (C) 2020-2025 Motagamwala Taha Arif Ali
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Sqlite Electron
2 |
3 | Sqlite Electron is a module for electron to use sqlite3 database without rebuilding it supports Windows (x64, x32) and Linux (x64, arm64). It supports ESM and CJS.
4 |
5 | Changes:
6 |
7 | *Backup the database using the new backup function.*
8 |
9 | ## Installation
10 |
11 | Use the package manager [npm](https://www.npmjs.com/package/sqlite-electron) to install Sqlite Electron.
12 |
13 | ```bash
14 | npm install sqlite-electron
15 | ```
16 |
17 | OR
18 |
19 | Use the package manager [yarn](https://yarnpkg.com/package/sqlite-electron) to install Sqlite Electron.
20 |
21 | ```bash
22 | yarn add sqlite-electron
23 | ```
24 |
25 | ## Notes
26 |
27 | *1. The package installs the prebuilt binaries of the sqlite on your system (if your system is supported) if you want any other platform binaries for a specific version go to https://github.com/tmotagam/sqlite-electron/releases.*
28 |
29 | *2. The examples written for this library disregards the required security for the electron apps so do not use it in your application.*
30 |
31 | *3. Never give values in the query string use values array for giving the values for the query not taking this precaution will result in sql injection attacks !.*
32 |
33 | Good parctice example
34 |
35 | ```javascript
36 | import { executeQuery } from "sqlite-electron";
37 | executeQuery(
38 | "INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (?, ?, ?, ?);",
39 | [var_name, var_age, var_address, var_salary]
40 | ); // Do this
41 | ```
42 |
43 | Bad parctice example:
44 |
45 | ```javascript
46 | import { executeQuery } from "sqlite-electron";
47 | executeQuery(
48 | `INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (${var_name}, ${var_age}, ${var_address}, ${var_salary});`
49 | ); // Never do this
50 | ```
51 |
52 | ## API`s
53 |
54 | | Api | Description |
55 | | ------------------------------------------------- | :-----------------------------------------------------------------------------------------------------------------------: |
56 | | setdbPath(path='', isuri=false) | It opens or creates the database for operation supports the InMemory databases and also SQLite URI format also the database path can be relative or absolute |
57 | | executeQuery(query = '', values = []) | It Executes single query with values they must be array |
58 | | executeMany(query = '', values = []) | It executes single query with multiple values |
59 | | executeScript(scriptname = '') | It execute the sql script scriptName must be name of the script or the script itself |
60 | | fetchAll(query = '', values = []) | It fetches all the values that matches the query. The values can also be given for the query using values array |
61 | | fetchOne(query = '', values = []) | It fetches only one value that matches the query. The values can also be given for the query using values array |
62 | | fetchMany(query = '', size = 5 values = []) | It fetches as many values as defined in size parameter that matches the query. The values can also be given for the query using values array
63 | | load_extension(path = '') | It loads SQLite extension from the given path for the connected database. |
64 | | backup(target='', pages=-1, name='main', sleep=0.250) | It backs up the database to the target database. The pages can be used if the database is very big. The name is used for the database to backup. Sleep is used to pause the operation for the specified seconds between backup of the specified number of pages. |
65 |
66 | ## Usage
67 |
68 | The sqlite-electron should only be used in main process in electron
69 |
70 | example:
71 |
72 | ```javascript
73 | const { app, BrowserWindow } = require("electron");
74 | const sqlite = require("sqlite-electron");
75 |
76 | function createWindow() {
77 | // Your Code
78 | }
79 | app.whenReady().then(() => {
80 | // Your Code
81 | });
82 |
83 | app.on("window-all-closed", () => {
84 | // Your Code
85 | });
86 | ```
87 |
88 | ### setdbPath
89 |
90 | This is a function for opening a existing database or creating a new database for operation.
91 |
92 | Call this function before calling the other 7 functions.
93 |
94 | ```javascript
95 | const { app, BrowserWindow, ipcMain } = require("electron");
96 | const sqlite = require("sqlite-electron");
97 |
98 | function createWindow() {
99 | // Your Code
100 | }
101 | app.whenReady().then(() => {
102 | // Your Code
103 | });
104 |
105 | app.on("window-all-closed", () => {
106 | // Your Code
107 | });
108 |
109 | ipcMain.handle("databasePath", async (event, dbPath) => {
110 | return await sqlite.setdbPath(dbPath);
111 | });
112 | ```
113 |
114 | You can create an In-memory database like this.
115 |
116 | ```javascript
117 | const { app, BrowserWindow, ipcMain } = require("electron");
118 | const sqlite = require("sqlite-electron");
119 |
120 | function createWindow() {
121 | // Your Code
122 | }
123 | app.whenReady().then(() => {
124 | // Your Code
125 | });
126 |
127 | app.on("window-all-closed", () => {
128 | // Your Code
129 | });
130 |
131 | ipcMain.handle("createInMemoryDatabase", async () => {
132 | return await sqlite.setdbPath(":memory:");
133 | });
134 | ```
135 |
136 | You can also use the SQLite URI format like this.
137 |
138 | ```javascript
139 | const { app, BrowserWindow, ipcMain } = require("electron");
140 | const sqlite = require("sqlite-electron");
141 |
142 | function createWindow() {
143 | // Your Code
144 | }
145 | app.whenReady().then(() => {
146 | // Your Code
147 | });
148 |
149 | app.on("window-all-closed", () => {
150 | // Your Code
151 | });
152 |
153 | ipcMain.handle("createDatabaseusingURI", async () => {
154 | return await sqlite.setdbPath("file:tutorial.db?mode:rw", isuri=true);
155 | });
156 | ```
157 |
158 | ### executeQuery
159 |
160 | This is the function for executing any single query eg: 'INSERT INTO tutorial (x) VALUES (?)' you can give values through the values array.
161 |
162 | ```javascript
163 | const { app, BrowserWindow, ipcMain } = require("electron");
164 | const sqlite = require("sqlite-electron");
165 |
166 | function createWindow() {
167 | // Your Code
168 | }
169 | app.whenReady().then(() => {
170 | // Your Code
171 | });
172 |
173 | app.on("window-all-closed", () => {
174 | // Your Code
175 | });
176 |
177 | ipcMain.handle("databasePath", async (event, dbPath) => {
178 | return await sqlite.setdbPath(dbPath);
179 | });
180 |
181 | ipcMain.handle("executeQuery", async (event, query, values) => {
182 | return await sqlite.executeQuery(query, values);
183 | });
184 | ```
185 |
186 | ### fetchAll
187 |
188 | This is the function for fetching all the rows that can be retrived using the given query eg: 'SELECT \* from tutorial' you can give values through the values array they will return the data in the Object format like this [{name: 'b', ...}, {name: 'a', ...}, {name: 'c', ...}].
189 |
190 | ```javascript
191 | const { app, BrowserWindow, ipcMain } = require("electron");
192 | const sqlite = require("sqlite-electron");
193 |
194 | function createWindow() {
195 | // Your Code
196 | }
197 | app.whenReady().then(() => {
198 | // Your Code
199 | });
200 |
201 | app.on("window-all-closed", () => {
202 | // Your Code
203 | });
204 |
205 | ipcMain.handle("databasePath", async (event, dbPath) => {
206 | return await sqlite.setdbPath(dbPath);
207 | });
208 |
209 | ipcMain.handle("fetchAll", async (event, query, values) => {
210 | return await sqlite.fetchAll(query, values);
211 | });
212 | ```
213 |
214 | ### fetchOne
215 |
216 | This is the function for fetching only one row that can be retrived using the given query eg: 'SELECT \* from tutorial WHERE ID=?' you can give values through the values array they will return the data in the Object format like this {name: 'a', ...}.
217 |
218 | ```javascript
219 | const { app, BrowserWindow, ipcMain } = require("electron");
220 | const sqlite = require("sqlite-electron");
221 |
222 | function createWindow() {
223 | // Your Code
224 | }
225 | app.whenReady().then(() => {
226 | // Your Code
227 | });
228 |
229 | app.on("window-all-closed", () => {
230 | // Your Code
231 | });
232 |
233 | ipcMain.handle("databasePath", async (event, dbPath) => {
234 | return await sqlite.setdbPath(dbPath);
235 | });
236 |
237 | ipcMain.handle("fetchOne", async (event, query, values) => {
238 | return await sqlite.fetchOne(query, values);
239 | });
240 | ```
241 |
242 | ### fetchMany
243 |
244 | This is the function for fetching as many rows as the size parameter allows that can be retrived using the given query eg: 'SELECT \* from tutorial WHERE name=?' you can give values through the values array they will return the data in the Object format like this [{name: 'a', ...}, {name: 'a', ...}, {name: 'a', ...}].
245 |
246 | ```javascript
247 | const { app, BrowserWindow, ipcMain } = require("electron");
248 | const sqlite = require("sqlite-electron");
249 |
250 | function createWindow() {
251 | // Your Code
252 | }
253 | app.whenReady().then(() => {
254 | // Your Code
255 | });
256 |
257 | app.on("window-all-closed", () => {
258 | // Your Code
259 | });
260 |
261 | ipcMain.handle("databasePath", async (event, dbPath) => {
262 | return await sqlite.setdbPath(dbPath);
263 | });
264 |
265 | ipcMain.handle("fetchMany", async (event, query, size, values) => {
266 | return await sqlite.fetchMany(query, size, values);
267 | });
268 | ```
269 |
270 | ### executeMany
271 |
272 | This is the function for executing query with multiple values.
273 |
274 | eg: ("INSERT INTO sqlite_main (NAME,AGE,ADDRESS,SALARY) VALUES (?, ?, ?, ?)", [["Pa", 32, "California", 20000.00], ["Pau", 32, "California", 20000.00], ["P", 32, "California", 20000.00], ["l", 32, "California", 20000.00]]) .
275 |
276 | ```javascript
277 | const { app, BrowserWindow, ipcMain } = require("electron");
278 | const sqlite = require("sqlite-electron");
279 |
280 | function createWindow() {
281 | // Your Code
282 | }
283 | app.whenReady().then(() => {
284 | // Your Code
285 | });
286 |
287 | app.on("window-all-closed", () => {
288 | // Your Code
289 | });
290 |
291 | ipcMain.handle("databasePath", async (event, dbPath) => {
292 | return await sqlite.setdbPath(dbPath);
293 | });
294 |
295 | ipcMain.handle("executeMany", async (event, query, values) => {
296 | return await sqlite.executeMany(query, values);
297 | });
298 | ```
299 |
300 | ### executeScript
301 |
302 | This is the function for executing multiple queries using sql scripts this function returns only true so never use any SELECT command in the sql scripts.
303 |
304 | You have to give absolute or relative path of the script or give the script`s content directly as well.
305 |
306 | eg: script.sql
307 |
308 | ```sql
309 | CREATE TABLE IF NOT EXISTS sqlite_main (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);
310 | ```
311 |
312 | ```javascript
313 | const { app, BrowserWindow, ipcMain } = require("electron");
314 | const sqlite = require("sqlite-electron");
315 |
316 | function createWindow() {
317 | // Your Code
318 | }
319 | app.whenReady().then(() => {
320 | // Your Code
321 | });
322 |
323 | app.on("window-all-closed", () => {
324 | // Your Code
325 | });
326 |
327 | ipcMain.handle("databasePath", async (event, dbPath) => {
328 | return await sqlite.setdbPath(dbPath);
329 | });
330 |
331 | ipcMain.handle("executeScript", async (event, scriptpath) => {
332 | return await sqlite.executeScript(scriptpath);
333 | // or
334 | return await sqlite.executeScript(
335 | "CREATE TABLE IF NOT EXISTS sqlite_main (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);"
336 | );
337 | });
338 | ```
339 |
340 | ### load_extension
341 |
342 | This function loads the SQLite extension from the given path for the connected database the path must be absolute.
343 |
344 | ```javascript
345 | const { app, BrowserWindow, ipcMain } = require("electron");
346 | const sqlite = require("sqlite-electron");
347 |
348 | function createWindow() {
349 | // Your Code
350 | }
351 | app.whenReady().then(() => {
352 | // Your Code
353 | });
354 |
355 | app.on("window-all-closed", () => {
356 | // Your Code
357 | });
358 |
359 | ipcMain.handle("databasePath", async (event, dbPath) => {
360 | return await sqlite.setdbPath(dbPath);
361 | });
362 |
363 | ipcMain.handle("load_extension", async (event, path) => {
364 | return await sqlite.load_extension(path);
365 | });
366 | ```
367 |
368 | ### backup
369 |
370 | Backup the database to another database the target database path can be relative or absolute.
371 |
372 | ```javascript
373 | const { app, BrowserWindow, ipcMain } = require("electron");
374 | const sqlite = require("sqlite-electron");
375 |
376 | function createWindow() {
377 | // Your Code
378 | }
379 | app.whenReady().then(() => {
380 | // Your Code
381 | });
382 |
383 | app.on("window-all-closed", () => {
384 | // Your Code
385 | });
386 |
387 | ipcMain.handle("databasePath", async (event, dbPath) => {
388 | return await sqlite.setdbPath(dbPath);
389 | });
390 |
391 | ipcMain.handle("backup", async (event, target, pages, name, sleep) => {
392 | return await backup(target, pages, name, sleep);
393 | });
394 | ```
395 |
396 | ## Example
397 |
398 | **[See sqlite-electron in action using electron 34.0.0](https://github.com/tmotagam/sqlite-electron/tree/master/example)**
399 |
400 | ## Contributing
401 |
402 | Pull requests and issues are welcome. For major changes, please open an issue first to discuss what you would like to change.
403 |
404 | [Github](https://github.com/tmotagam/sqlite-electron)
405 |
406 | ## License
407 |
408 | [GPL v3.0](https://choosealicense.com/licenses/gpl-3.0/)
409 |
--------------------------------------------------------------------------------
/SECURITY.md:
--------------------------------------------------------------------------------
1 | # Security issue reporting & disclosure process
2 |
3 | If you feel you have found a security issue or concern with sqlite-electron, please reach out to Me.
4 |
5 | Email Me at .
6 |
7 | I will try to communicate in a timely manner and address your concerns.
--------------------------------------------------------------------------------
/binaries/sqlite-linux-x64:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tmotagam/sqlite-electron/6bbf151da6fb5f7b4b055a6f98748e8dc1d1d5ec/binaries/sqlite-linux-x64
--------------------------------------------------------------------------------
/binaries/sqlite-win32-ia32.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tmotagam/sqlite-electron/6bbf151da6fb5f7b4b055a6f98748e8dc1d1d5ec/binaries/sqlite-win32-ia32.exe
--------------------------------------------------------------------------------
/binaries/sqlite-win32-x64.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tmotagam/sqlite-electron/6bbf151da6fb5f7b4b055a6f98748e8dc1d1d5ec/binaries/sqlite-win32-x64.exe
--------------------------------------------------------------------------------
/cjs/sqlite-electron.js:
--------------------------------------------------------------------------------
1 | "use strict";
2 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4 | return new (P || (P = Promise))(function (resolve, reject) {
5 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8 | step((generator = generator.apply(thisArg, _arguments || [])).next());
9 | });
10 | };
11 | var __generator = (this && this.__generator) || function (thisArg, body) {
12 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13 | return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14 | function verb(n) { return function (v) { return step([n, v]); }; }
15 | function step(op) {
16 | if (f) throw new TypeError("Generator is already executing.");
17 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
18 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19 | if (y = 0, t) op = [op[0] & 2, t.value];
20 | switch (op[0]) {
21 | case 0: case 1: t = op; break;
22 | case 4: _.label++; return { value: op[1], done: false };
23 | case 5: _.label++; y = op[1]; op = [0]; continue;
24 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
25 | default:
26 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30 | if (t[2]) _.ops.pop();
31 | _.trys.pop(); continue;
32 | }
33 | op = body.call(thisArg, _);
34 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36 | }
37 | };
38 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
39 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
40 | if (ar || !(i in from)) {
41 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
42 | ar[i] = from[i];
43 | }
44 | }
45 | return to.concat(ar || Array.prototype.slice.call(from));
46 | };
47 | Object.defineProperty(exports, "__esModule", { value: true });
48 | exports.backup = exports.load_extension = exports.executeScript = exports.executeMany = exports.fetchAll = exports.fetchMany = exports.fetchOne = exports.executeQuery = exports.setdbPath = void 0;
49 | var child_process_1 = require("child_process");
50 | var path_1 = require("path");
51 | var sqlite = null;
52 | var exitHandler = function () {
53 | if (sqlite !== null) {
54 | sqlite.kill();
55 | }
56 | };
57 | var setdbPath = function (path_2) {
58 | var args_1 = [];
59 | for (var _i = 1; _i < arguments.length; _i++) {
60 | args_1[_i - 1] = arguments[_i];
61 | }
62 | return __awaiter(void 0, __spreadArray([path_2], args_1, true), void 0, function (path, isuri) {
63 | var sqlitePath;
64 | if (isuri === void 0) { isuri = false; }
65 | return __generator(this, function (_a) {
66 | if (sqlite === null) {
67 | sqlitePath = "";
68 | if (process.platform === "win32") {
69 | sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch, ".exe"));
70 | }
71 | else {
72 | sqlitePath = (0, path_1.join)(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch));
73 | }
74 | sqlite = (0, child_process_1.execFile)(sqlitePath, { maxBuffer: 10 * 1024 * 1024 });
75 | if (sqlite !== null) {
76 | process.on("exit", exitHandler.bind(null));
77 | process.on("SIGINT", exitHandler.bind(null));
78 | process.on("SIGUSR1", exitHandler.bind(null));
79 | process.on("SIGUSR2", exitHandler.bind(null));
80 | process.on("uncaughtException", function () {
81 | exitHandler.bind(null);
82 | });
83 | }
84 | }
85 | return [2, new Promise(function (resolve, reject) {
86 | try {
87 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
88 | return reject("Sqlite not defined");
89 | }
90 | var string_1 = "";
91 | var onData_1 = function (data) {
92 | string_1 += data.toString();
93 | if (string_1.substring(string_1.length - 3) === "EOF") {
94 | resolve(JSON.parse(string_1.split("EOF")[0]));
95 | sqlite.stdout.off("data", onData_1);
96 | }
97 | };
98 | sqlite.stdout.on("data", onData_1);
99 | sqlite.stdin.write("".concat(JSON.stringify(["newConnection", path, isuri]), "\n"));
100 | }
101 | catch (error) {
102 | reject(error);
103 | }
104 | })];
105 | });
106 | });
107 | };
108 | exports.setdbPath = setdbPath;
109 | var executeQuery = function (query_1) {
110 | var args_1 = [];
111 | for (var _i = 1; _i < arguments.length; _i++) {
112 | args_1[_i - 1] = arguments[_i];
113 | }
114 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
115 | if (values === void 0) { values = []; }
116 | return __generator(this, function (_a) {
117 | return [2, new Promise(function (resolve, reject) {
118 | try {
119 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
120 | return reject("Sqlite not defined");
121 | }
122 | var string_2 = "";
123 | var onData_2 = function (data) {
124 | string_2 += data.toString();
125 | if (string_2.substring(string_2.length - 3) === "EOF") {
126 | resolve(JSON.parse(string_2.split("EOF")[0]));
127 | sqlite.stdout.off("data", onData_2);
128 | }
129 | };
130 | sqlite.stdout.on("data", onData_2);
131 | for (var i = 0; i < values.length; i++) {
132 | if (!Buffer.isBuffer(values[i])) {
133 | continue;
134 | }
135 | values[i] = JSON.stringify(values[i]);
136 | }
137 | sqlite.stdin.write("".concat(JSON.stringify(["executeQuery", query, values]), "\n"));
138 | }
139 | catch (error) {
140 | reject(error);
141 | }
142 | })];
143 | });
144 | });
145 | };
146 | exports.executeQuery = executeQuery;
147 | var fetchAll = function (query_1) {
148 | var args_1 = [];
149 | for (var _i = 1; _i < arguments.length; _i++) {
150 | args_1[_i - 1] = arguments[_i];
151 | }
152 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
153 | if (values === void 0) { values = []; }
154 | return __generator(this, function (_a) {
155 | return [2, new Promise(function (resolve, reject) {
156 | try {
157 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
158 | return reject("Sqlite not defined");
159 | }
160 | var string_3 = "";
161 | var onData_3 = function (data) {
162 | string_3 += data.toString();
163 | if (string_3.substring(string_3.length - 3) === "EOF") {
164 | var d = JSON.parse(string_3.split("EOF")[0]);
165 | var _loop_1 = function (i) {
166 | var de = d[i];
167 | Object.keys(de).forEach(function (i) {
168 | var element = de[i];
169 | if (typeof element === "object" &&
170 | !Array.isArray(element) &&
171 | element !== null &&
172 | element.type == "Buffer" &&
173 | Array.isArray(element.data)) {
174 | de[i] = Buffer.from(element.data);
175 | }
176 | });
177 | };
178 | for (var i = 0; i < d.length; i++) {
179 | _loop_1(i);
180 | }
181 | if (string_3.startsWith('"Error: ')) {
182 | reject(d);
183 | }
184 | else {
185 | resolve(d);
186 | }
187 | sqlite.stdout.off("data", onData_3);
188 | }
189 | };
190 | sqlite.stdout.on("data", onData_3);
191 | for (var i = 0; i < values.length; i++) {
192 | if (!Buffer.isBuffer(values[i])) {
193 | continue;
194 | }
195 | values[i] = JSON.stringify(values[i]);
196 | }
197 | sqlite.stdin.write("".concat(JSON.stringify(["fetchall", query, values]), "\n"));
198 | }
199 | catch (error) {
200 | reject(error);
201 | }
202 | })];
203 | });
204 | });
205 | };
206 | exports.fetchAll = fetchAll;
207 | var fetchOne = function (query_1) {
208 | var args_1 = [];
209 | for (var _i = 1; _i < arguments.length; _i++) {
210 | args_1[_i - 1] = arguments[_i];
211 | }
212 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
213 | if (values === void 0) { values = []; }
214 | return __generator(this, function (_a) {
215 | return [2, new Promise(function (resolve, reject) {
216 | try {
217 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
218 | return reject("Sqlite not defined");
219 | }
220 | var string_4 = "";
221 | var onData_4 = function (data) {
222 | string_4 += data.toString();
223 | if (string_4.substring(string_4.length - 3) === "EOF") {
224 | var d_1 = JSON.parse(string_4.split("EOF")[0]);
225 | Object.keys(d_1).forEach(function (key) {
226 | var element = d_1[key];
227 | if (typeof element === "object" &&
228 | !Array.isArray(element) &&
229 | element !== null &&
230 | element.type == "Buffer" &&
231 | Array.isArray(element.data)) {
232 | d_1[key] = Buffer.from(element.data);
233 | }
234 | });
235 | if (string_4.startsWith('"Error: ')) {
236 | reject(d_1);
237 | }
238 | else {
239 | resolve(d_1);
240 | }
241 | sqlite.stdout.off("data", onData_4);
242 | }
243 | };
244 | sqlite.stdout.on("data", onData_4);
245 | for (var i = 0; i < values.length; i++) {
246 | if (!Buffer.isBuffer(values[i])) {
247 | continue;
248 | }
249 | values[i] = JSON.stringify(values[i]);
250 | }
251 | sqlite.stdin.write("".concat(JSON.stringify(["fetchone", query, values]), "\n"));
252 | }
253 | catch (error) {
254 | reject(error);
255 | }
256 | })];
257 | });
258 | });
259 | };
260 | exports.fetchOne = fetchOne;
261 | var fetchMany = function (query_1, size_1) {
262 | var args_1 = [];
263 | for (var _i = 2; _i < arguments.length; _i++) {
264 | args_1[_i - 2] = arguments[_i];
265 | }
266 | return __awaiter(void 0, __spreadArray([query_1, size_1], args_1, true), void 0, function (query, size, values) {
267 | if (values === void 0) { values = []; }
268 | return __generator(this, function (_a) {
269 | return [2, new Promise(function (resolve, reject) {
270 | try {
271 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
272 | return reject("Sqlite not defined");
273 | }
274 | var string_5 = "";
275 | var onData_5 = function (data) {
276 | string_5 += data.toString();
277 | if (string_5.substring(string_5.length - 3) === "EOF") {
278 | var d = JSON.parse(string_5.split("EOF")[0]);
279 | var _loop_2 = function (i) {
280 | var de = d[i];
281 | Object.keys(de).forEach(function (i) {
282 | var element = de[i];
283 | if (typeof element === "object" &&
284 | !Array.isArray(element) &&
285 | element !== null &&
286 | element.type == "Buffer" &&
287 | Array.isArray(element.data)) {
288 | de[i] = Buffer.from(element.data);
289 | }
290 | });
291 | };
292 | for (var i = 0; i < d.length; i++) {
293 | _loop_2(i);
294 | }
295 | if (string_5.startsWith('"Error: ')) {
296 | reject(d);
297 | }
298 | else {
299 | resolve(d);
300 | }
301 | sqlite.stdout.off("data", onData_5);
302 | }
303 | };
304 | sqlite.stdout.on("data", onData_5);
305 | for (var i = 0; i < values.length; i++) {
306 | if (!Buffer.isBuffer(values[i])) {
307 | continue;
308 | }
309 | values[i] = JSON.stringify(values[i]);
310 | }
311 | sqlite.stdin.write("".concat(JSON.stringify(["fetchmany", query, size, values]), "\n"));
312 | }
313 | catch (error) {
314 | reject(error);
315 | }
316 | })];
317 | });
318 | });
319 | };
320 | exports.fetchMany = fetchMany;
321 | var executeMany = function (query, values) { return __awaiter(void 0, void 0, void 0, function () {
322 | return __generator(this, function (_a) {
323 | return [2, new Promise(function (resolve, reject) {
324 | try {
325 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
326 | return reject("Sqlite not defined");
327 | }
328 | var string_6 = "";
329 | var onData_6 = function (data) {
330 | string_6 += data.toString();
331 | if (string_6.substring(string_6.length - 3) === "EOF") {
332 | resolve(JSON.parse(string_6.split("EOF")[0]));
333 | sqlite.stdout.off("data", onData_6);
334 | }
335 | };
336 | sqlite.stdout.on("data", onData_6);
337 | for (var i = 0; i < values.length; i++) {
338 | for (var j = 0; j < values[i].length; j++) {
339 | if (!Buffer.isBuffer(values[i][j])) {
340 | continue;
341 | }
342 | values[i][j] = JSON.stringify(values[i][j]);
343 | }
344 | }
345 | sqlite.stdin.write("".concat(JSON.stringify(["executeMany", query, values]), "\n"));
346 | }
347 | catch (error) {
348 | reject(error);
349 | }
350 | })];
351 | });
352 | }); };
353 | exports.executeMany = executeMany;
354 | var executeScript = function (scriptname) { return __awaiter(void 0, void 0, void 0, function () {
355 | return __generator(this, function (_a) {
356 | return [2, new Promise(function (resolve, reject) {
357 | try {
358 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
359 | return reject("Sqlite not defined");
360 | }
361 | var string_7 = "";
362 | var onData_7 = function (data) {
363 | string_7 += data.toString();
364 | if (string_7.substring(string_7.length - 3) === "EOF") {
365 | resolve(JSON.parse(string_7.split("EOF")[0]));
366 | sqlite.stdout.off("data", onData_7);
367 | }
368 | };
369 | sqlite.stdout.on("data", onData_7);
370 | sqlite.stdin.write("".concat(JSON.stringify(["executeScript", scriptname]), "\n"));
371 | }
372 | catch (error) {
373 | reject(error);
374 | }
375 | })];
376 | });
377 | }); };
378 | exports.executeScript = executeScript;
379 | var load_extension = function (path) { return __awaiter(void 0, void 0, void 0, function () {
380 | return __generator(this, function (_a) {
381 | return [2, new Promise(function (resolve, reject) {
382 | try {
383 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
384 | return reject("Sqlite not defined");
385 | }
386 | var string_8 = "";
387 | var onData_8 = function (data) {
388 | string_8 += data.toString();
389 | if (string_8.substring(string_8.length - 3) === "EOF") {
390 | resolve(JSON.parse(string_8.split("EOF")[0]));
391 | sqlite.stdout.off("data", onData_8);
392 | }
393 | };
394 | sqlite.stdout.on("data", onData_8);
395 | sqlite.stdin.write("".concat(JSON.stringify(["load_extension", path]), "\n"));
396 | }
397 | catch (error) {
398 | reject(error);
399 | }
400 | })];
401 | });
402 | }); };
403 | exports.load_extension = load_extension;
404 | var backup = function (target_1) {
405 | var args_1 = [];
406 | for (var _i = 1; _i < arguments.length; _i++) {
407 | args_1[_i - 1] = arguments[_i];
408 | }
409 | return __awaiter(void 0, __spreadArray([target_1], args_1, true), void 0, function (target, pages, name, sleep) {
410 | if (pages === void 0) { pages = -1; }
411 | if (name === void 0) { name = "main"; }
412 | if (sleep === void 0) { sleep = 0.250; }
413 | return __generator(this, function (_a) {
414 | return [2, new Promise(function (resolve, reject) {
415 | try {
416 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
417 | return reject("Sqlite not defined");
418 | }
419 | var string_9 = "";
420 | var onData_9 = function (data) {
421 | string_9 += data.toString();
422 | if (string_9.substring(string_9.length - 3) === "EOF") {
423 | resolve(JSON.parse(string_9.split("EOF")[0]));
424 | sqlite.stdout.off("data", onData_9);
425 | }
426 | };
427 | sqlite.stdout.on("data", onData_9);
428 | sqlite.stdin.write("".concat(JSON.stringify(["backup", target, pages, name, sleep]), "\n"));
429 | }
430 | catch (error) {
431 | reject(error);
432 | }
433 | })];
434 | });
435 | });
436 | };
437 | exports.backup = backup;
438 |
--------------------------------------------------------------------------------
/esm/sqlite-electron.mjs:
--------------------------------------------------------------------------------
1 | var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3 | return new (P || (P = Promise))(function (resolve, reject) {
4 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7 | step((generator = generator.apply(thisArg, _arguments || [])).next());
8 | });
9 | };
10 | var __generator = (this && this.__generator) || function (thisArg, body) {
11 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
12 | return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
13 | function verb(n) { return function (v) { return step([n, v]); }; }
14 | function step(op) {
15 | if (f) throw new TypeError("Generator is already executing.");
16 | while (g && (g = 0, op[0] && (_ = 0)), _) try {
17 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
18 | if (y = 0, t) op = [op[0] & 2, t.value];
19 | switch (op[0]) {
20 | case 0: case 1: t = op; break;
21 | case 4: _.label++; return { value: op[1], done: false };
22 | case 5: _.label++; y = op[1]; op = [0]; continue;
23 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
24 | default:
25 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
26 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
27 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
28 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
29 | if (t[2]) _.ops.pop();
30 | _.trys.pop(); continue;
31 | }
32 | op = body.call(thisArg, _);
33 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
34 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
35 | }
36 | };
37 | var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
38 | if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
39 | if (ar || !(i in from)) {
40 | if (!ar) ar = Array.prototype.slice.call(from, 0, i);
41 | ar[i] = from[i];
42 | }
43 | }
44 | return to.concat(ar || Array.prototype.slice.call(from));
45 | };
46 | import { execFile } from "child_process";
47 | import { join } from "path";
48 | var sqlite = null;
49 | var exitHandler = function () {
50 | if (sqlite !== null) {
51 | sqlite.kill();
52 | }
53 | };
54 | var setdbPath = function (path_1) {
55 | var args_1 = [];
56 | for (var _i = 1; _i < arguments.length; _i++) {
57 | args_1[_i - 1] = arguments[_i];
58 | }
59 | return __awaiter(void 0, __spreadArray([path_1], args_1, true), void 0, function (path, isuri) {
60 | var sqlitePath;
61 | if (isuri === void 0) { isuri = false; }
62 | return __generator(this, function (_a) {
63 | if (sqlite === null) {
64 | sqlitePath = "";
65 | if (process.platform === "win32") {
66 | sqlitePath = join(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch, ".exe"));
67 | }
68 | else {
69 | sqlitePath = join(__dirname, "..", "sqlite-".concat(process.platform, "-").concat(process.arch), "sqlite-".concat(process.platform, "-").concat(process.arch));
70 | }
71 | sqlite = execFile(sqlitePath, { maxBuffer: 10 * 1024 * 1024 });
72 | if (sqlite !== null) {
73 | process.on("exit", exitHandler.bind(null));
74 | process.on("SIGINT", exitHandler.bind(null));
75 | process.on("SIGUSR1", exitHandler.bind(null));
76 | process.on("SIGUSR2", exitHandler.bind(null));
77 | process.on("uncaughtException", function () {
78 | exitHandler.bind(null);
79 | });
80 | }
81 | }
82 | return [2, new Promise(function (resolve, reject) {
83 | try {
84 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
85 | return reject("Sqlite not defined");
86 | }
87 | var string_1 = "";
88 | var onData_1 = function (data) {
89 | string_1 += data.toString();
90 | if (string_1.substring(string_1.length - 3) === "EOF") {
91 | resolve(JSON.parse(string_1.split("EOF")[0]));
92 | sqlite.stdout.off("data", onData_1);
93 | }
94 | };
95 | sqlite.stdout.on("data", onData_1);
96 | sqlite.stdin.write("".concat(JSON.stringify(["newConnection", path, isuri]), "\n"));
97 | }
98 | catch (error) {
99 | reject(error);
100 | }
101 | })];
102 | });
103 | });
104 | };
105 | var executeQuery = function (query_1) {
106 | var args_1 = [];
107 | for (var _i = 1; _i < arguments.length; _i++) {
108 | args_1[_i - 1] = arguments[_i];
109 | }
110 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
111 | if (values === void 0) { values = []; }
112 | return __generator(this, function (_a) {
113 | return [2, new Promise(function (resolve, reject) {
114 | try {
115 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
116 | return reject("Sqlite not defined");
117 | }
118 | var string_2 = "";
119 | var onData_2 = function (data) {
120 | string_2 += data.toString();
121 | if (string_2.substring(string_2.length - 3) === "EOF") {
122 | resolve(JSON.parse(string_2.split("EOF")[0]));
123 | sqlite.stdout.off("data", onData_2);
124 | }
125 | };
126 | sqlite.stdout.on("data", onData_2);
127 | for (var i = 0; i < values.length; i++) {
128 | if (!Buffer.isBuffer(values[i])) {
129 | continue;
130 | }
131 | values[i] = JSON.stringify(values[i]);
132 | }
133 | sqlite.stdin.write("".concat(JSON.stringify(["executeQuery", query, values]), "\n"));
134 | }
135 | catch (error) {
136 | reject(error);
137 | }
138 | })];
139 | });
140 | });
141 | };
142 | var fetchAll = function (query_1) {
143 | var args_1 = [];
144 | for (var _i = 1; _i < arguments.length; _i++) {
145 | args_1[_i - 1] = arguments[_i];
146 | }
147 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
148 | if (values === void 0) { values = []; }
149 | return __generator(this, function (_a) {
150 | return [2, new Promise(function (resolve, reject) {
151 | try {
152 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
153 | return reject("Sqlite not defined");
154 | }
155 | var string_3 = "";
156 | var onData_3 = function (data) {
157 | string_3 += data.toString();
158 | if (string_3.substring(string_3.length - 3) === "EOF") {
159 | var d = JSON.parse(string_3.split("EOF")[0]);
160 | var _loop_1 = function (i) {
161 | var de = d[i];
162 | Object.keys(de).forEach(function (i) {
163 | var element = de[i];
164 | if (typeof element === "object" &&
165 | !Array.isArray(element) &&
166 | element !== null &&
167 | element.type == "Buffer" &&
168 | Array.isArray(element.data)) {
169 | de[i] = Buffer.from(element.data);
170 | }
171 | });
172 | };
173 | for (var i = 0; i < d.length; i++) {
174 | _loop_1(i);
175 | }
176 | if (string_3.startsWith('"Error: ')) {
177 | reject(d);
178 | }
179 | else {
180 | resolve(d);
181 | }
182 | sqlite.stdout.off("data", onData_3);
183 | }
184 | };
185 | sqlite.stdout.on("data", onData_3);
186 | for (var i = 0; i < values.length; i++) {
187 | if (!Buffer.isBuffer(values[i])) {
188 | continue;
189 | }
190 | values[i] = JSON.stringify(values[i]);
191 | }
192 | sqlite.stdin.write("".concat(JSON.stringify(["fetchall", query, values]), "\n"));
193 | }
194 | catch (error) {
195 | reject(error);
196 | }
197 | })];
198 | });
199 | });
200 | };
201 | var fetchOne = function (query_1) {
202 | var args_1 = [];
203 | for (var _i = 1; _i < arguments.length; _i++) {
204 | args_1[_i - 1] = arguments[_i];
205 | }
206 | return __awaiter(void 0, __spreadArray([query_1], args_1, true), void 0, function (query, values) {
207 | if (values === void 0) { values = []; }
208 | return __generator(this, function (_a) {
209 | return [2, new Promise(function (resolve, reject) {
210 | try {
211 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
212 | return reject("Sqlite not defined");
213 | }
214 | var string_4 = "";
215 | var onData_4 = function (data) {
216 | string_4 += data.toString();
217 | if (string_4.substring(string_4.length - 3) === "EOF") {
218 | var d_1 = JSON.parse(string_4.split("EOF")[0]);
219 | Object.keys(d_1).forEach(function (key) {
220 | var element = d_1[key];
221 | if (typeof element === "object" &&
222 | !Array.isArray(element) &&
223 | element !== null &&
224 | element.type == "Buffer" &&
225 | Array.isArray(element.data)) {
226 | d_1[key] = Buffer.from(element.data);
227 | }
228 | });
229 | if (string_4.startsWith('"Error: ')) {
230 | reject(d_1);
231 | }
232 | else {
233 | resolve(d_1);
234 | }
235 | sqlite.stdout.off("data", onData_4);
236 | }
237 | };
238 | sqlite.stdout.on("data", onData_4);
239 | for (var i = 0; i < values.length; i++) {
240 | if (!Buffer.isBuffer(values[i])) {
241 | continue;
242 | }
243 | values[i] = JSON.stringify(values[i]);
244 | }
245 | sqlite.stdin.write("".concat(JSON.stringify(["fetchone", query, values]), "\n"));
246 | }
247 | catch (error) {
248 | reject(error);
249 | }
250 | })];
251 | });
252 | });
253 | };
254 | var fetchMany = function (query_1, size_1) {
255 | var args_1 = [];
256 | for (var _i = 2; _i < arguments.length; _i++) {
257 | args_1[_i - 2] = arguments[_i];
258 | }
259 | return __awaiter(void 0, __spreadArray([query_1, size_1], args_1, true), void 0, function (query, size, values) {
260 | if (values === void 0) { values = []; }
261 | return __generator(this, function (_a) {
262 | return [2, new Promise(function (resolve, reject) {
263 | try {
264 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
265 | return reject("Sqlite not defined");
266 | }
267 | var string_5 = "";
268 | var onData_5 = function (data) {
269 | string_5 += data.toString();
270 | if (string_5.substring(string_5.length - 3) === "EOF") {
271 | var d = JSON.parse(string_5.split("EOF")[0]);
272 | var _loop_2 = function (i) {
273 | var de = d[i];
274 | Object.keys(de).forEach(function (i) {
275 | var element = de[i];
276 | if (typeof element === "object" &&
277 | !Array.isArray(element) &&
278 | element !== null &&
279 | element.type == "Buffer" &&
280 | Array.isArray(element.data)) {
281 | de[i] = Buffer.from(element.data);
282 | }
283 | });
284 | };
285 | for (var i = 0; i < d.length; i++) {
286 | _loop_2(i);
287 | }
288 | if (string_5.startsWith('"Error: ')) {
289 | reject(d);
290 | }
291 | else {
292 | resolve(d);
293 | }
294 | sqlite.stdout.off("data", onData_5);
295 | }
296 | };
297 | sqlite.stdout.on("data", onData_5);
298 | for (var i = 0; i < values.length; i++) {
299 | if (!Buffer.isBuffer(values[i])) {
300 | continue;
301 | }
302 | values[i] = JSON.stringify(values[i]);
303 | }
304 | sqlite.stdin.write("".concat(JSON.stringify(["fetchmany", query, size, values]), "\n"));
305 | }
306 | catch (error) {
307 | reject(error);
308 | }
309 | })];
310 | });
311 | });
312 | };
313 | var executeMany = function (query, values) { return __awaiter(void 0, void 0, void 0, function () {
314 | return __generator(this, function (_a) {
315 | return [2, new Promise(function (resolve, reject) {
316 | try {
317 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
318 | return reject("Sqlite not defined");
319 | }
320 | var string_6 = "";
321 | var onData_6 = function (data) {
322 | string_6 += data.toString();
323 | if (string_6.substring(string_6.length - 3) === "EOF") {
324 | resolve(JSON.parse(string_6.split("EOF")[0]));
325 | sqlite.stdout.off("data", onData_6);
326 | }
327 | };
328 | sqlite.stdout.on("data", onData_6);
329 | for (var i = 0; i < values.length; i++) {
330 | for (var j = 0; j < values[i].length; j++) {
331 | if (!Buffer.isBuffer(values[i][j])) {
332 | continue;
333 | }
334 | values[i][j] = JSON.stringify(values[i][j]);
335 | }
336 | }
337 | sqlite.stdin.write("".concat(JSON.stringify(["executeMany", query, values]), "\n"));
338 | }
339 | catch (error) {
340 | reject(error);
341 | }
342 | })];
343 | });
344 | }); };
345 | var executeScript = function (scriptname) { return __awaiter(void 0, void 0, void 0, function () {
346 | return __generator(this, function (_a) {
347 | return [2, new Promise(function (resolve, reject) {
348 | try {
349 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
350 | return reject("Sqlite not defined");
351 | }
352 | var string_7 = "";
353 | var onData_7 = function (data) {
354 | string_7 += data.toString();
355 | if (string_7.substring(string_7.length - 3) === "EOF") {
356 | resolve(JSON.parse(string_7.split("EOF")[0]));
357 | sqlite.stdout.off("data", onData_7);
358 | }
359 | };
360 | sqlite.stdout.on("data", onData_7);
361 | sqlite.stdin.write("".concat(JSON.stringify(["executeScript", scriptname]), "\n"));
362 | }
363 | catch (error) {
364 | reject(error);
365 | }
366 | })];
367 | });
368 | }); };
369 | var load_extension = function (path) { return __awaiter(void 0, void 0, void 0, function () {
370 | return __generator(this, function (_a) {
371 | return [2, new Promise(function (resolve, reject) {
372 | try {
373 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
374 | return reject("Sqlite not defined");
375 | }
376 | var string_8 = "";
377 | var onData_8 = function (data) {
378 | string_8 += data.toString();
379 | if (string_8.substring(string_8.length - 3) === "EOF") {
380 | resolve(JSON.parse(string_8.split("EOF")[0]));
381 | sqlite.stdout.off("data", onData_8);
382 | }
383 | };
384 | sqlite.stdout.on("data", onData_8);
385 | sqlite.stdin.write("".concat(JSON.stringify(["load_extension", path]), "\n"));
386 | }
387 | catch (error) {
388 | reject(error);
389 | }
390 | })];
391 | });
392 | }); };
393 | var backup = function (target_1) {
394 | var args_1 = [];
395 | for (var _i = 1; _i < arguments.length; _i++) {
396 | args_1[_i - 1] = arguments[_i];
397 | }
398 | return __awaiter(void 0, __spreadArray([target_1], args_1, true), void 0, function (target, pages, name, sleep) {
399 | if (pages === void 0) { pages = -1; }
400 | if (name === void 0) { name = "main"; }
401 | if (sleep === void 0) { sleep = 0.250; }
402 | return __generator(this, function (_a) {
403 | return [2, new Promise(function (resolve, reject) {
404 | try {
405 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
406 | return reject("Sqlite not defined");
407 | }
408 | var string_9 = "";
409 | var onData_9 = function (data) {
410 | string_9 += data.toString();
411 | if (string_9.substring(string_9.length - 3) === "EOF") {
412 | resolve(JSON.parse(string_9.split("EOF")[0]));
413 | sqlite.stdout.off("data", onData_9);
414 | }
415 | };
416 | sqlite.stdout.on("data", onData_9);
417 | sqlite.stdin.write("".concat(JSON.stringify(["backup", target, pages, name, sleep]), "\n"));
418 | }
419 | catch (error) {
420 | reject(error);
421 | }
422 | })];
423 | });
424 | });
425 | };
426 | export { setdbPath, executeQuery, fetchOne, fetchMany, fetchAll, executeMany, executeScript, load_extension, backup };
427 |
--------------------------------------------------------------------------------
/example/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | sqlite-electron-demo for showing sqlite-electron in action using electron 15.3.0
635 | Copyright (C) 2022-2025 Motagamwala Taha Arif Ali
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | sqlite-electron-demo Copyright (C) 2022-2025 Motagamwala Taha Arif Ali
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
--------------------------------------------------------------------------------
/example/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | Demo
7 |
8 |
9 |
10 |
11 |
sqlite-electron Demo
12 |
13 | We are using Node.js ,
14 | Chromium ,
15 | and Electron .
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 |
102 |
103 |
104 |
105 |
106 |
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 |
122 |
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/example/index.js:
--------------------------------------------------------------------------------
1 | const { app, BrowserWindow, ipcMain } = require("electron");
2 | const { join } = require("path");
3 | const { setdbPath, executeQuery, executeMany, executeScript, fetchOne, fetchMany, fetchAll, load_extension, backup } = require("sqlite-electron");
4 |
5 | function createWindow() {
6 | const win = new BrowserWindow({
7 | width: 800,
8 | height: 600,
9 | webPreferences: {
10 | preload: join(__dirname, "preload.js"),
11 | },
12 | });
13 |
14 | win.loadFile("index.html");
15 | }
16 | app.enableSandbox();
17 | app.whenReady().then(() => {
18 | createWindow();
19 |
20 | app.on("activate", () => {
21 | if (BrowserWindow.getAllWindows().length === 0) {
22 | createWindow();
23 | }
24 | });
25 | });
26 |
27 | app.on("window-all-closed", () => {
28 | if (process.platform !== "darwin") {
29 | app.quit();
30 | }
31 | });
32 |
33 | ipcMain.handle("potd", async (event, dbPath, isuri) => {
34 | try {
35 | return await setdbPath(dbPath, isuri)
36 | } catch (error) {
37 | return error
38 | }
39 | });
40 |
41 | ipcMain.handle("executeQuery", async (event, query, value) => {
42 | try {
43 | return await executeQuery(query, value);
44 | } catch (error) {
45 | return error;
46 | }
47 | });
48 |
49 | ipcMain.handle("fetchone", async (event, query, value) => {
50 | try {
51 | return await fetchOne(query, value);
52 | } catch (error) {
53 | return error;
54 | }
55 | });
56 |
57 | ipcMain.handle("fetchmany", async (event, query, size, value) => {
58 | try {
59 | return await fetchMany(query, size, value);
60 | } catch (error) {
61 | return error;
62 | }
63 | });
64 |
65 | ipcMain.handle("fetchall", async (event, query, value) => {
66 | try {
67 | return await fetchAll(query, value);
68 | } catch (error) {
69 | return error;
70 | }
71 | });
72 |
73 | ipcMain.handle("executeMany", async (event, query, values) => {
74 | try {
75 | return await executeMany(query, values);
76 | } catch (error) {
77 | return error;
78 | }
79 | });
80 |
81 | ipcMain.handle("executeScript", async (event, scriptpath) => {
82 | try {
83 | return await executeScript(scriptpath);
84 | } catch (error) {
85 | return error;
86 | }
87 | });
88 |
89 | ipcMain.handle("load_extension", async (event, path) => {
90 | try {
91 | return await load_extension(path);
92 | } catch (error) {
93 | return error;
94 | }
95 | });
96 |
97 | ipcMain.handle("backup", async (event, target, pages, name, sleep) => {
98 | try {
99 | return await backup(target, Number(pages), name, Number(sleep));
100 | } catch (error) {
101 | return error;
102 | }
103 | });
104 |
--------------------------------------------------------------------------------
/example/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "test",
3 | "version": "3.6.0",
4 | "description": "",
5 | "main": "index.js",
6 | "scripts": {
7 | "start": "electron .",
8 | "test": "echo \"Error: no test specified\" && exit 1"
9 | },
10 | "keywords": [],
11 | "author": "Motagamwala Taha Arif Ali",
12 | "license": "ISC",
13 | "devDependencies": {
14 | "electron": "^34.0.0",
15 | "@electron/packager": "^18.3.6"
16 | },
17 | "browser": {
18 | "fs": false,
19 | "path": false,
20 | "os": false
21 | },
22 | "dependencies": {
23 | "sqlite-electron": "^3.2.0"
24 | }
25 | }
--------------------------------------------------------------------------------
/example/preload.js:
--------------------------------------------------------------------------------
1 | const { contextBridge, ipcRenderer } = require('electron')
2 |
3 | window.addEventListener('DOMContentLoaded', async () => {
4 | const replaceText = (selector, text) => {
5 | const element = document.getElementById(selector)
6 | if (element) element.innerText = text
7 | }
8 |
9 | for (const type of ['chrome', 'node', 'electron']) {
10 | replaceText(`${type}-version`, process.versions[type])
11 | }
12 | })
13 |
14 | contextBridge.exposeInMainWorld('api', {
15 | path: async () => {
16 | const path = document.getElementById('dbpath').value
17 | const isuri = document.getElementById('isuri').checked
18 | try {
19 | const res = await ipcRenderer.invoke('potd', path, isuri);
20 | document.getElementById('pout').innerText = 'Output: ' + res;
21 | } catch (error) {
22 | document.getElementById('pout').innerText = 'Output: ' + error;
23 | }
24 | },
25 | equery: async () => {
26 | const query = document.getElementById('singlequery').value
27 | const values = document.getElementById('value').value
28 | try {
29 | const arr = JSON.parse("[" + values + "]");
30 | const res = await ipcRenderer.invoke('executeQuery', query, arr[0]);
31 | document.getElementById('pout1').innerText = 'Output: ' + res;
32 | } catch (error) {
33 | document.getElementById('pout1').innerText = 'Output: ' + error;
34 | }
35 | },
36 | fetchall: async () => {
37 | const query = document.getElementById('fetchallquery').value
38 | const values = document.getElementById('fetchallvalue').value
39 | try {
40 | const arr = JSON.parse("[" + values + "]");
41 | const res = await ipcRenderer.invoke('fetchall', query, arr[0]);
42 | document.getElementById('poutfa').innerText = 'Output: ' + JSON.stringify(res);
43 | } catch (error) {
44 | document.getElementById('poutfa').innerText = 'Output: ' + error;
45 | }
46 | },
47 | fetchone: async () => {
48 | const query = document.getElementById('fetchonequery').value
49 | const values = document.getElementById('fetchonevalue').value
50 | try {
51 | const arr = JSON.parse("[" + values + "]");
52 | const res = await ipcRenderer.invoke('fetchone', query, arr[0]);
53 | document.getElementById('poutfo').innerText = 'Output: ' + JSON.stringify(res);
54 | } catch (error) {
55 | document.getElementById('poutfo').innerText = 'Output: ' + error;
56 | }
57 | },
58 | fetchmany: async () => {
59 | const query = document.getElementById('fetchmanyquery').value
60 | const values = document.getElementById('fetchmanyvalue').value
61 | const size = Number(document.getElementById('fetchmanysize').value)
62 | try {
63 | const arr = JSON.parse("[" + values + "]");
64 | const res = await ipcRenderer.invoke('fetchmany', query, size, arr[0]);
65 | document.getElementById('poutfm').innerText = 'Output: ' + JSON.stringify(res);
66 | } catch (error) {
67 | document.getElementById('poutfm').innerText = 'Output: ' + error;
68 | }
69 | },
70 | mquery: async () => {
71 | const query = document.getElementById('query').value
72 | const values = document.getElementById('values').value
73 | try {
74 | const arr = JSON.parse("[" + values + "]");
75 | const res = await ipcRenderer.invoke('executeMany', query, arr[0]);
76 | document.getElementById('pout2').innerText = 'Output: ' + res;
77 | } catch (error) {
78 | document.getElementById('pout2').innerText = 'Output: ' + error;
79 | }
80 | },
81 | escript: async () => {
82 | const spath = document.getElementById('scriptPath').value
83 | const res = await ipcRenderer.invoke('executeScript', spath);
84 | document.getElementById('pout3').innerText = 'Output: ' + res;
85 | },
86 | load_extension: async () => {
87 | const path = document.getElementById('extensionPath').value
88 | const res = await ipcRenderer.invoke('load_extension', path);
89 | console.log(res);
90 | document.getElementById('pout4').innerText = 'Output: ' + res;
91 | },
92 | backup: async () => {
93 | const target = document.getElementById('backupPath').value
94 | const pages = document.getElementById('pages').value
95 | const name = document.getElementById('name').value
96 | const sleep = document.getElementById('sleep').value
97 | const res = await ipcRenderer.invoke('backup', target, pages, name, sleep);
98 | console.log(res);
99 | document.getElementById('pout5').innerText = 'Output: ' + res;
100 | }
101 | })
--------------------------------------------------------------------------------
/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sqlite-electron",
3 | "version": "3.2.0",
4 | "lockfileVersion": 3
5 | }
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sqlite-electron",
3 | "version": "3.2.0",
4 | "description": "A module for electron to use sqlite3 without rebuilding",
5 | "main": "./cjs/sqlite-electron.js",
6 | "module": "./esm.sqlite-electron.mjs",
7 | "types": "./sqlite-electron.d.ts",
8 | "scripts": {
9 | "postinstall": "node ./scripts/postinstall.js"
10 | },
11 | "exports": {
12 | "types": "./sqlite-electron.d.ts",
13 | "import": "./esm/sqlite-electron.mjs",
14 | "require": "./cjs/sqlite-electron.js"
15 | },
16 | "author": "Motagamwala Taha Arif Ali",
17 | "files": [
18 | "cjs",
19 | "esm",
20 | "sqlite-electron.d.ts",
21 | "scripts"
22 | ],
23 | "license": "GPL-3.0-or-later",
24 | "keywords": [
25 | "sqlite-electron",
26 | "sqlite3",
27 | "sqlite",
28 | "electron",
29 | "database"
30 | ],
31 | "repository": {
32 | "url": "git+https://github.com/tmotagam/sqlite-electron.git"
33 | }
34 | }
--------------------------------------------------------------------------------
/scripts/postinstall.js:
--------------------------------------------------------------------------------
1 | /*
2 | Postinstall Script for sqlite-electron module
3 | Copyright (C) 2022-2025 Motagamwala Taha Arif Ali
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | const https = require('https');
20 | const fs = require('fs');
21 | const { resolve, dirname } = require('path')
22 |
23 | const extract = require('./dependencies')
24 |
25 | if (process.platform === 'win32') {
26 | const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.zip`);
27 | https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip`, (response) => {
28 | if (response.statusCode === 200) {
29 | response.pipe(file);
30 | file.on("finish", async () => {
31 | file.close();
32 | console.log("Download Completed")
33 | await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) })
34 | console.log("Extraction Completed")
35 | fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`))
36 | });
37 | } else if (response.statusCode === 302) {
38 | https.get(response.headers.location, (response) => {
39 | if (response.statusCode === 200) {
40 | response.pipe(file);
41 | file.on("finish", async () => {
42 | file.close();
43 | console.log("Download Completed")
44 | await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) })
45 | console.log("Extraction Completed")
46 | fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`))
47 | });
48 | } else {
49 | throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip` }
50 | }
51 | })
52 | } else {
53 | throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip` }
54 | }
55 | }).on("error", (e) => {
56 | throw e
57 | })
58 | } else {
59 | const file = fs.createWriteStream(`./sqlite-${process.platform}-${process.arch}.zip`);
60 | https.get(`https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip`, (response) => {
61 | if (response.statusCode === 200) {
62 | response.pipe(file);
63 | file.on("finish", async () => {
64 | file.close();
65 | console.log("Download Completed")
66 | await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) })
67 | console.log("Extraction Completed")
68 | fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`))
69 | fs.chmodSync(resolve(`./sqlite-${process.platform}-${process.arch}/sqlite-${process.platform}-${process.arch}`), 0o744)
70 | });
71 | } else if (response.statusCode === 302) {
72 | https.get(response.headers.location, (response) => {
73 | if (response.statusCode === 200) {
74 | response.pipe(file);
75 | file.on("finish", async () => {
76 | file.close();
77 | console.log("Download Completed")
78 | await extract(resolve(`./sqlite-${process.platform}-${process.arch}.zip`), { dir: dirname(resolve(`./sqlite-${process.platform}-${process.arch}.zip`)) })
79 | console.log("Extraction Completed")
80 | fs.unlinkSync(resolve(`./sqlite-${process.platform}-${process.arch}.zip`))
81 | fs.chmodSync(resolve(`./sqlite-${process.platform}-${process.arch}/sqlite-${process.platform}-${process.arch}`), 0o744)
82 | });
83 | } else {
84 | throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip` }
85 | }
86 | })
87 | } else {
88 | throw { code: response.statusCode, message: response.statusMessage, url: `https://github.com/tmotagam/sqlite-electron/releases/download/v3.2.0/sqlite-${process.platform}-${process.arch}.zip` }
89 | }
90 | }).on("error", (e) => {
91 | throw e
92 | })
93 | }
94 |
--------------------------------------------------------------------------------
/sqlite-electron.d.ts:
--------------------------------------------------------------------------------
1 | /*
2 | Types for sqlite-electron modules
3 | Copyright (C) 2020-2025 Motagamwala Taha Arif Ali
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | */
18 |
19 | /**
20 | * setdbPath function allows for connecting to the database.
21 | *
22 | * @param {string} path - Relative path of a database since it constructs absolute path by itself
23 | * @param {boolean} isuri - true if path is a URL
24 | * @return {Promise} boolean
25 | *
26 | * @example
27 | *
28 | * setdbPath(path='./path/to/db/path.db')
29 | * setdbPath(path=':memory:') // In-memory database
30 | * setdbPath(path='file:tutorial.db?mode=ro', isuri=true) // Opening read-only database using SQLite URI
31 | */
32 | export declare function setdbPath(
33 | path: string,
34 | isuri?: boolean
35 | ): Promise;
36 |
37 | /**
38 | * executeQuery function executes only one query.
39 | *
40 | * @param {string} query - SQL query
41 | * @param {Array} values - An optional param for values used in a SQL query
42 | * @return {Promise} boolean
43 | *
44 | * @example
45 | *
46 | * executeQuery(query='CREATE TABLE sqlite_master (name, email, joining_date, salary)')
47 | * executeQuery(query='INSERT INTO sqlite_master (name, email, joining_date, salary) values(?,?,?,?)', values=['John Doe','example@sqlite-electron.com','1250-12-19',8000000])
48 | */
49 | export declare function executeQuery(
50 | query: string,
51 | values?: Array
52 | ): Promise;
53 |
54 | /**
55 | * Fetches all the records from the database based on the given query
56 | * and returns the result as an array of the specified type.
57 | *
58 | * @param {string} query the SQL query to be executed
59 | * @param {Array} values optional array of values to be used in the query
60 | * @return {Promise>} A promise that resolves to an array of objects of the specified type.
61 | */
62 | export declare function fetchAll(
63 | query: string,
64 | values?: Array
65 | ): Promise>;
66 |
67 | /**
68 | * Fetches single records from the database based on the given query
69 | * and returns the result as an object of the specified type.
70 | *
71 | * @param {string} query The SQL query to execute.
72 | * @param {Array} values Optional values to bind to the query parameters.
73 | * @return {Promise} A promise that resolves to an object of the specified type.
74 | */
75 | export declare function fetchOne(
76 | query: string,
77 | values?: Array
78 | ): Promise;
79 |
80 | /**
81 | * Fetches multiple records from the database based on the given query
82 | * and returns the result as an array of the specified type.
83 | *
84 | * @param {string} query The query to execute on the database.
85 | * @param {number} size The number of records to fetch.
86 | * @param {Array} values Optional values to be used in the query parameters.
87 | * @return {Promise>} A promise that resolves to an array of object of the specified type.
88 | */
89 | export declare function fetchMany(
90 | query: string,
91 | size: number,
92 | values?: Array
93 | ): Promise>;
94 |
95 | /**
96 | * executeMany function executes only one query on multiple values useful for bulk write.
97 | *
98 | * @param {string} query - SQL query
99 | * @param {Array>} values - A param for values used in a SQL query
100 | * @return {Promise} boolean
101 | *
102 | * @example
103 | *
104 | * executeMany(query='INSERT INTO sqlite_master (name, email, joining_date, salary) values(?,?,?,?)', values=[['John Doe','example@sqlite-electron.com','1250-12-19',8000000], ['John Doe','example@sqlite-electron.com','1250-12-19',8000000]])
105 | */
106 | export declare function executeMany(
107 | query: string,
108 | values: Array>
109 | ): Promise;
110 |
111 | /**
112 | * executeScript function executes all the queries given in the sql script.
113 | *
114 | * @param {string} scriptname - A path param for sql script or sql script itself
115 | * @return {Promise} boolean
116 | *
117 | * @example
118 | *
119 | * executeScript(scriptname='C://database//script.sql')
120 | * executeScript(scriptname='CREATE TABLE IF NOT EXISTS comp (ID INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,NAME TEXT NOT NULL,AGE INT NOT NULL,ADDRESS CHAR(50) NOT NULL,SALARY REAL NOT NULL);')
121 | */
122 | export declare function executeScript(scriptname: string): Promise;
123 |
124 | /**
125 | * load_extension function loads an extension into the database.
126 | *
127 | * @param {string} path - Path of the extension
128 | * @return {Promise} boolean
129 | *
130 | * @example
131 | *
132 | * load_extension(path='./fts5')
133 | */
134 | export declare function load_extension(path: string): Promise;
135 |
136 | /**
137 | * backup function creates a backup of the database.
138 | *
139 | * @param {string} target - The database connection to save the backup to.
140 | * @param {number} pages - The number of pages to copy at a time. If equal to or less than 0, the entire database is copied in a single step. Defaults to -1.
141 | * @param {string} name - The name of the database to back up. Either "main" (the default) for the main database, "temp" for the temporary database, or the name of a custom database as attached using the ATTACH DATABASE SQL statement.
142 | * @param {number} sleep - The number of seconds to sleep between successive attempts to back up remaining pages.
143 | * @return {Promise} boolean
144 | *
145 | * @example
146 | *
147 | * backup(target='./backup.db', pages=10, name='main', sleep=10)
148 | */
149 | export declare function backup(target: string, pages?: number, name?: string, sleep?: number): Promise;
150 |
--------------------------------------------------------------------------------
/sqlite-electron.ts:
--------------------------------------------------------------------------------
1 | import { ChildProcess, execFile } from "child_process";
2 | import { join } from "path";
3 | import { Type } from "typescript";
4 |
5 | let sqlite: ChildProcess | null = null;
6 |
7 | const exitHandler = () => {
8 | if (sqlite !== null) {
9 | sqlite.kill();
10 | }
11 | };
12 |
13 | const setdbPath = async (path: string, isuri = false): Promise => {
14 | if (sqlite === null) {
15 | let sqlitePath = "";
16 | if (process.platform === "win32") {
17 | sqlitePath = join(
18 | __dirname,
19 | "..",
20 | `sqlite-${process.platform}-${process.arch}`,
21 | `sqlite-${process.platform}-${process.arch}.exe`
22 | );
23 | } else {
24 | sqlitePath = join(
25 | __dirname,
26 | "..",
27 | `sqlite-${process.platform}-${process.arch}`,
28 | `sqlite-${process.platform}-${process.arch}`
29 | );
30 | }
31 | sqlite = execFile(sqlitePath, { maxBuffer: 10 * 1024 * 1024 });
32 | if (sqlite !== null) {
33 | //Exit when app is closing
34 | process.on("exit", exitHandler.bind(null));
35 |
36 | //catches ctrl+c event
37 | process.on("SIGINT", exitHandler.bind(null));
38 |
39 | // catches "kill pid" (for example: nodemon restart)
40 | process.on("SIGUSR1", exitHandler.bind(null));
41 | process.on("SIGUSR2", exitHandler.bind(null));
42 |
43 | //catches uncaught exceptions
44 | process.on("uncaughtException", () => {
45 | exitHandler.bind(null);
46 | });
47 | }
48 | }
49 | return new Promise((resolve, reject) => {
50 | try {
51 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
52 | return reject("Sqlite not defined");
53 | }
54 | let string = "";
55 | const onData = (data: Buffer) => {
56 | string += data.toString();
57 | if (string.substring(string.length - 3) === "EOF") {
58 | resolve(JSON.parse(string.split("EOF")[0]));
59 | sqlite.stdout.off("data", onData);
60 | }
61 | };
62 | sqlite.stdout.on("data", onData);
63 | sqlite.stdin.write(`${JSON.stringify(["newConnection", path, isuri])}\n`);
64 | } catch (error) {
65 | reject(error);
66 | }
67 | });
68 | };
69 |
70 | const executeQuery = async (
71 | query: string,
72 | values: Array = []
73 | ): Promise => {
74 | return new Promise((resolve, reject) => {
75 | try {
76 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
77 | return reject("Sqlite not defined");
78 | }
79 | let string = "";
80 | const onData = (data: Buffer) => {
81 | string += data.toString();
82 | if (string.substring(string.length - 3) === "EOF") {
83 | resolve(JSON.parse(string.split("EOF")[0]));
84 | sqlite.stdout.off("data", onData);
85 | }
86 | };
87 |
88 | sqlite.stdout.on("data", onData);
89 | for (let i = 0; i < values.length; i++) {
90 | if (!Buffer.isBuffer(values[i])) {
91 | continue;
92 | }
93 | values[i] = JSON.stringify(values[i]);
94 | }
95 | sqlite.stdin.write(
96 | `${JSON.stringify(["executeQuery", query, values])}\n`
97 | );
98 | } catch (error) {
99 | reject(error);
100 | }
101 | });
102 | };
103 |
104 | const fetchAll = async (
105 | query: string,
106 | values: Array = []
107 | ): Promise> => {
108 | return new Promise((resolve, reject) => {
109 | try {
110 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
111 | return reject("Sqlite not defined");
112 | }
113 | let string = "";
114 | const onData = (data: Buffer) => {
115 | string += data.toString();
116 | if (string.substring(string.length - 3) === "EOF") {
117 | const d = JSON.parse(string.split("EOF")[0]);
118 | for (let i = 0; i < d.length; i++) {
119 | const de = d[i];
120 | Object.keys(de).forEach((i) => {
121 | const element = de[i];
122 | if (
123 | typeof element === "object" &&
124 | !Array.isArray(element) &&
125 | element !== null &&
126 | element.type == "Buffer" &&
127 | Array.isArray(element.data)
128 | ) {
129 | de[i] = Buffer.from(element.data);
130 | }
131 | });
132 | }
133 | if (string.startsWith('"Error: ')) {
134 | reject(d);
135 | } else {
136 | resolve(d);
137 | }
138 | sqlite.stdout.off("data", onData);
139 | }
140 | };
141 |
142 | sqlite.stdout.on("data", onData);
143 | for (let i = 0; i < values.length; i++) {
144 | if (!Buffer.isBuffer(values[i])) {
145 | continue;
146 | }
147 | values[i] = JSON.stringify(values[i]);
148 | }
149 | sqlite.stdin.write(`${JSON.stringify(["fetchall", query, values])}\n`);
150 | } catch (error) {
151 | reject(error);
152 | }
153 | });
154 | };
155 |
156 | const fetchOne = async (
157 | query: string,
158 | values: Array = []
159 | ): Promise => {
160 | return new Promise((resolve, reject) => {
161 | try {
162 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
163 | return reject("Sqlite not defined");
164 | }
165 | let string = "";
166 | const onData = (data: Buffer) => {
167 | string += data.toString();
168 | if (string.substring(string.length - 3) === "EOF") {
169 | const d = JSON.parse(string.split("EOF")[0]);
170 | Object.keys(d).forEach((key) => {
171 | const element = d[key];
172 | if (
173 | typeof element === "object" &&
174 | !Array.isArray(element) &&
175 | element !== null &&
176 | element.type == "Buffer" &&
177 | Array.isArray(element.data)
178 | ) {
179 | d[key] = Buffer.from(element.data);
180 | }
181 | });
182 | if (string.startsWith('"Error: ')) {
183 | reject(d);
184 | } else {
185 | resolve(d);
186 | }
187 | sqlite.stdout.off("data", onData);
188 | }
189 | };
190 |
191 | sqlite.stdout.on("data", onData);
192 | for (let i = 0; i < values.length; i++) {
193 | if (!Buffer.isBuffer(values[i])) {
194 | continue;
195 | }
196 | values[i] = JSON.stringify(values[i]);
197 | }
198 | sqlite.stdin.write(`${JSON.stringify(["fetchone", query, values])}\n`);
199 | } catch (error) {
200 | reject(error);
201 | }
202 | });
203 | };
204 |
205 | const fetchMany = async (
206 | query: string,
207 | size: number,
208 | values: Array = []
209 | ): Promise> => {
210 | return new Promise((resolve, reject) => {
211 | try {
212 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
213 | return reject("Sqlite not defined");
214 | }
215 | let string = "";
216 | const onData = (data: Buffer) => {
217 | string += data.toString();
218 | if (string.substring(string.length - 3) === "EOF") {
219 | const d = JSON.parse(string.split("EOF")[0]);
220 | for (let i = 0; i < d.length; i++) {
221 | const de = d[i];
222 | Object.keys(de).forEach((i) => {
223 | const element = de[i];
224 | if (
225 | typeof element === "object" &&
226 | !Array.isArray(element) &&
227 | element !== null &&
228 | element.type == "Buffer" &&
229 | Array.isArray(element.data)
230 | ) {
231 | de[i] = Buffer.from(element.data);
232 | }
233 | });
234 | }
235 | if (string.startsWith('"Error: ')) {
236 | reject(d);
237 | } else {
238 | resolve(d);
239 | }
240 | sqlite.stdout.off("data", onData);
241 | }
242 | };
243 |
244 | sqlite.stdout.on("data", onData);
245 | for (let i = 0; i < values.length; i++) {
246 | if (!Buffer.isBuffer(values[i])) {
247 | continue;
248 | }
249 | values[i] = JSON.stringify(values[i]);
250 | }
251 | sqlite.stdin.write(
252 | `${JSON.stringify(["fetchmany", query, size, values])}\n`
253 | );
254 | } catch (error) {
255 | reject(error);
256 | }
257 | });
258 | };
259 |
260 | const executeMany = async (
261 | query: string,
262 | values: Array>
263 | ): Promise => {
264 | return new Promise((resolve, reject) => {
265 | try {
266 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
267 | return reject("Sqlite not defined");
268 | }
269 | let string = "";
270 | const onData = (data: Buffer) => {
271 | string += data.toString();
272 | if (string.substring(string.length - 3) === "EOF") {
273 | resolve(JSON.parse(string.split("EOF")[0]));
274 | sqlite.stdout.off("data", onData);
275 | }
276 | };
277 |
278 | sqlite.stdout.on("data", onData);
279 | for (let i = 0; i < values.length; i++) {
280 | for (let j = 0; j < values[i].length; j++) {
281 | if (!Buffer.isBuffer(values[i][j])) {
282 | continue;
283 | }
284 | values[i][j] = JSON.stringify(values[i][j]);
285 | }
286 | }
287 | sqlite.stdin.write(`${JSON.stringify(["executeMany", query, values])}\n`);
288 | } catch (error) {
289 | reject(error);
290 | }
291 | });
292 | };
293 |
294 | const executeScript = async (scriptname: string): Promise => {
295 | return new Promise((resolve, reject) => {
296 | try {
297 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
298 | return reject("Sqlite not defined");
299 | }
300 | let string = "";
301 | const onData = (data: Buffer) => {
302 | string += data.toString();
303 | if (string.substring(string.length - 3) === "EOF") {
304 | resolve(JSON.parse(string.split("EOF")[0]));
305 | sqlite.stdout.off("data", onData);
306 | }
307 | };
308 |
309 | sqlite.stdout.on("data", onData);
310 | sqlite.stdin.write(`${JSON.stringify(["executeScript", scriptname])}\n`);
311 | } catch (error) {
312 | reject(error);
313 | }
314 | });
315 | };
316 |
317 | const load_extension = async (path: string): Promise => {
318 | return new Promise((resolve, reject) => {
319 | try {
320 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
321 | return reject("Sqlite not defined");
322 | }
323 | let string = "";
324 | const onData = (data: Buffer) => {
325 | string += data.toString();
326 | if (string.substring(string.length - 3) === "EOF") {
327 | resolve(JSON.parse(string.split("EOF")[0]));
328 | sqlite.stdout.off("data", onData);
329 | }
330 | };
331 |
332 | sqlite.stdout.on("data", onData);
333 | sqlite.stdin.write(`${JSON.stringify(["load_extension", path])}\n`);
334 | } catch (error) {
335 | reject(error);
336 | }
337 | });
338 | };
339 |
340 | const backup = async (target: string, pages: number = -1, name: string = "main", sleep: number = 0.250): Promise => {
341 | return new Promise((resolve, reject) => {
342 | try {
343 | if (sqlite === null || sqlite.stdin === null || sqlite.stdout === null) {
344 | return reject("Sqlite not defined");
345 | }
346 | let string = "";
347 | const onData = (data: Buffer) => {
348 | string += data.toString();
349 | if (string.substring(string.length - 3) === "EOF") {
350 | resolve(JSON.parse(string.split("EOF")[0]));
351 | sqlite.stdout.off("data", onData);
352 | }
353 | };
354 |
355 | sqlite.stdout.on("data", onData);
356 | sqlite.stdin.write(`${JSON.stringify(["backup", target, pages, name, sleep])}\n`);
357 | } catch (error) {
358 | reject(error);
359 | }
360 | });
361 | }
362 |
363 | export {
364 | setdbPath,
365 | executeQuery,
366 | fetchOne,
367 | fetchMany,
368 | fetchAll,
369 | executeMany,
370 | executeScript,
371 | load_extension,
372 | backup
373 | };
374 |
--------------------------------------------------------------------------------
/sqlite.py:
--------------------------------------------------------------------------------
1 | """
2 | sqlite-electorn server executing the sql queries of the nodejs/electron processes
3 | Copyright (C) 2020-2025 Motagamwala Taha Arif Ali
4 |
5 | This program is free software: you can redistribute it and/or modify
6 | it under the terms of the GNU General Public License as published by
7 | the Free Software Foundation, either version 3 of the License, or
8 | (at your option) any later version.
9 |
10 | This program is distributed in the hope that it will be useful,
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | GNU General Public License for more details.
14 |
15 | You should have received a copy of the GNU General Public License
16 | along with this program. If not, see .
17 | """
18 |
19 | import array
20 | import sys, json, sqlite3
21 |
22 | conn = None
23 |
24 | class ConnectionNotSetUpException(Exception):
25 | pass
26 |
27 | def decodebytes(data: dict):
28 | """
29 | Decodes bytes values in a dictionary by converting them to a list of integers.
30 |
31 | Args:
32 | data (dict): The dictionary containing the bytes values.
33 |
34 | Returns:
35 | dict: The dictionary with the bytes values replaced by a dictionary with the type "Buffer" and the data as a list of integers.
36 |
37 | Example:
38 | >>> data = {'a': b'hello', 'b': b'world'}
39 | >>> decodebytes(data)
40 | {'a': {'type': 'Buffer', 'data': [104, 101, 108, 108, 111]}, 'b': {'type': 'Buffer', 'data': [119, 111, 114, 108, 100]}}
41 | """
42 | for key, val in data.items():
43 | if type(val) is bytes:
44 | data[key] = {"type": "Buffer", "data": list(val)}
45 | return data
46 |
47 | def encodebytes(data: list):
48 | """
49 | Encodes a list of data by converting elements to array objects based on specific conditions.
50 |
51 | Parameters:
52 | data (list): A list of data to encode.
53 |
54 | Returns:
55 | list: The encoded data list.
56 | """
57 | for i, val in enumerate(data):
58 | try:
59 | v = json.loads(val)
60 | if type(v) is dict:
61 | if "data" in v and "type" in v:
62 | if v["type"] == "Buffer" and type(v["data"]) is list:
63 | data[i] = array.array("B", v["data"])
64 | except Exception:
65 | pass
66 | return data
67 |
68 | def newConnection(db: str, isuri: bool):
69 | """
70 | Function for establishing a new connection to the database.
71 |
72 | Parameters:
73 | db (str): The path of the database to connect to.
74 | isuri (bool): Indicates whether the database path is a URI or not.
75 |
76 | Returns:
77 | bool: True if the connection is successfully established, otherwise returns an error message.
78 | """
79 | try:
80 | global conn
81 | if conn == None:
82 | conn = sqlite3.connect(db, uri=isuri)
83 | conn.row_factory = sqlite3.Row
84 | return True
85 | else:
86 | conn.close()
87 | conn = sqlite3.connect(db, uri=isuri)
88 | conn.row_factory = sqlite3.Row
89 | return True
90 | except Exception as e:
91 | return "Error: " + str(e)
92 |
93 | def executeQuery(sql: str, values: list):
94 | """
95 | Executes an SQL query on the database connection.
96 |
97 | Parameters:
98 | sql (str): The SQL query to execute.
99 | values (list): The list of values to bind to the query.
100 |
101 | Returns:
102 | bool: True if the query was executed successfully, otherwise an error message.
103 |
104 | Raises:
105 | ConnectionNotSetUpException: If the database connection is not set up.
106 | """
107 | try:
108 | if conn == None:
109 | raise ConnectionNotSetUpException("Connection not set up")
110 |
111 | if not(not values):
112 | values = encodebytes(values)
113 | conn.execute(sql, values)
114 | conn.commit()
115 | return True
116 |
117 | else:
118 | conn.execute(sql)
119 | conn.commit()
120 | return True
121 |
122 | except Exception as e:
123 | return "Error: " + str(e)
124 |
125 | def fetchall(sql: str, values: list):
126 | """
127 | Fetches all rows from the database that match the given SQL query and values.
128 |
129 | Args:
130 | sql (str): The SQL query to execute.
131 | values (list): The list of values to bind to the query.
132 |
133 | Returns:
134 | list: A list of dictionaries representing the fetched rows. Each dictionary contains the column names as keys and their corresponding values.
135 | str: If an error occurs during the execution of the query, a string with the error message is returned.
136 |
137 | Raises:
138 | ConnectionNotSetUpException: If the database connection is not set up.
139 | """
140 | try:
141 | if conn == None:
142 | raise ConnectionNotSetUpException("Connection not set up")
143 |
144 | if not(not values):
145 | values = encodebytes(values)
146 | return [decodebytes(dict(i)) for i in conn.execute(sql, values).fetchall()]
147 |
148 | else:
149 | return [decodebytes(dict(i)) for i in conn.execute(sql).fetchall()]
150 |
151 | except Exception as e:
152 | return "Error: " + str(e)
153 |
154 | def fetchone(sql: str, values: list):
155 | """
156 | Fetches a single row from the database that matches the given SQL query and values.
157 |
158 | Args:
159 | sql (str): The SQL query to execute.
160 | values (list): The list of values to bind to the query.
161 |
162 | Returns:
163 | dict: A dictionary representing the fetched row. The dictionary contains the column names as keys and their corresponding values.
164 | str: If an error occurs during the execution of the query, a string with the error message is returned.
165 |
166 | Raises:
167 | ConnectionNotSetUpException: If the database connection is not set up.
168 | """
169 | try:
170 | if conn == None:
171 | raise ConnectionNotSetUpException("Connection not set up")
172 |
173 | if not(not values):
174 | values = encodebytes(values)
175 | return decodebytes(dict(conn.execute(sql, values).fetchone()))
176 |
177 | else:
178 | return decodebytes(dict(conn.execute(sql).fetchone()))
179 |
180 | except Exception as e:
181 | return "Error: " + str(e)
182 |
183 | def fetchmany(sql: str, size: int, values: list):
184 | """
185 | Fetches multiple rows from the database that match the given SQL query and values.
186 |
187 | Args:
188 | sql (str): The SQL query to execute.
189 | size (int): The number of rows to fetch.
190 | values (list): The list of values to bind to the query.
191 |
192 | Returns:
193 | list: A list of dictionaries representing the fetched rows. Each dictionary contains the column names as keys and their corresponding values.
194 | str: If an error occurs during the execution of the query, a string with the error message is returned.
195 |
196 | Raises:
197 | ConnectionNotSetUpException: If the database connection is not set up.
198 | """
199 | try:
200 | if conn == None:
201 | raise ConnectionNotSetUpException("Connection not set up")
202 |
203 | if not(not values):
204 | values = encodebytes(values)
205 | return [decodebytes(dict(i)) for i in conn.execute(sql, values).fetchmany(size)]
206 |
207 | else:
208 | return [decodebytes(dict(i)) for i in conn.execute(sql).fetchmany(size)]
209 |
210 | except Exception as e:
211 | return "Error: " + str(e)
212 |
213 | def executeMany(sql: str, values: list):
214 | """
215 | Executes a SQL query with multiple sets of values on the database connection.
216 |
217 | Args:
218 | sql (str): The SQL query to execute.
219 | values (list): A list of lists containing the values to bind to the query.
220 |
221 | Returns:
222 | bool: True if the query was executed successfully, False otherwise.
223 |
224 | Raises:
225 | ConnectionNotSetUpException: If the database connection is not set up.
226 |
227 | Note:
228 | The values parameter should be a list of lists, where each inner list contains the values for a single row.
229 |
230 | Example:
231 | executeMany("INSERT INTO table (column1, column2) VALUES (?, ?)", [[value1, value2], [value3, value4]])
232 | """
233 | try:
234 | if conn == None:
235 | raise ConnectionNotSetUpException("Connection not set up")
236 |
237 | for i in range(0, values.__len__()):
238 | values[i] = encodebytes(values[i])
239 | conn.executemany(sql, (values))
240 | conn.commit()
241 | return True
242 |
243 | except Exception as e:
244 | return "Error: " + str(e)
245 |
246 | def executeScript(sqlScript: str):
247 | """
248 | Executes a SQL script on the database connection.
249 |
250 | Args:
251 | sqlScript (str): The path to the SQL script file.
252 |
253 | Returns:
254 | bool or str: True if the script was executed successfully, otherwise an error message.
255 |
256 | Raises:
257 | ConnectionNotSetUpException: If the database connection is not set up.
258 | """
259 | try:
260 | if conn == None:
261 | raise ConnectionNotSetUpException("Connection not set up")
262 | with open(sqlScript, "r") as sql_file:
263 | sql = sql_file.read()
264 |
265 | conn.executescript(sql)
266 | conn.commit()
267 | return True
268 |
269 | except Exception as e:
270 | try:
271 | if conn == None:
272 | raise ConnectionNotSetUpException("Connection not set up")
273 | conn.executescript(sqlScript)
274 | conn.commit()
275 | return True
276 | except Exception as e:
277 | return "Error: " + str(e)
278 |
279 | def load_extension(name: str):
280 | """
281 | This function loads an extension into the database.
282 |
283 | Args:
284 | name (str): The name of the extension to load.
285 |
286 | Returns:
287 | bool or str: True if the extension is loaded successfully, otherwise a string containing the error message.
288 |
289 | Raises:
290 | ConnectionNotSetUpException: If the database connection is not set up.
291 | """
292 | try:
293 | if conn == None:
294 | raise ConnectionNotSetUpException("Connection not set up")
295 |
296 | conn.enable_load_extension(True)
297 | conn.load_extension(name)
298 | conn.enable_load_extension(False)
299 | return True
300 |
301 | except Exception as e:
302 | return "Error: " + str(e)
303 |
304 | def backup(target: str, pages: int, name: str, sleep: int):
305 | """
306 | This function creates a backup of the database.
307 |
308 | Args:
309 | target (str): The database connection to save the backup to.
310 | pages (int): The number of pages to copy at a time. If equal to or less than 0, the entire database is copied in a single step. Defaults to -1.
311 | name (str): The name of the database to back up. Either "main" (the default) for the main database, "temp" for the temporary database, or the name of a custom database as attached using the ATTACH DATABASE SQL statement.
312 | sleep (float): The number of seconds to sleep between successive attempts to back up remaining pages.
313 |
314 | Returns:
315 | bool or str: True if the backup is created successfully, otherwise a string containing the error message.
316 |
317 | Raises:
318 | ConnectionNotSetUpException: If the database connection is not set up.
319 | """
320 |
321 | try:
322 | if conn == None:
323 | raise ConnectionNotSetUpException("Connection not set up")
324 |
325 | dst = sqlite3.connect(target)
326 |
327 | conn.backup(dst, pages=pages, name=name, sleep=sleep)
328 | dst.close()
329 | return True
330 |
331 | except Exception as e:
332 | return "Error: " + str(e)
333 |
334 | def main():
335 | """
336 | The main driver function reading from the input send by nodejs process and executing the sql queries on the database returning the data in JSON format.
337 |
338 | This function reads lines of input from the standard input, processes them, and writes the results to the standard output in JSON format. The input lines are expected to be in the form of a JSON array with the first element being the command name and the remaining elements being the arguments for the command.
339 |
340 | The supported commands are:
341 | - "newConnection": Creates a new database connection.
342 | - "executeQuery": Executes an SQL query on the database.
343 | - "fetchAll": Fetches all rows from the result of an executed SQL query.
344 | - "fetchMany": Fetches a number of rows from the result of an executed SQL query.
345 | - "fetchOne": Fetches a single row from the result of an executed SQL query.
346 | - "executeMany": Executes an SQL query with multiple sets of parameters.
347 | - "executeScript": Executes an SQL script file.
348 | - "load_extension": Loads an SQL extension into the database.
349 | - "backup": Creates a backup of the database.
350 |
351 | The function reads lines of input from the standard input until it encounters a newline character. It then processes the input line by parsing it as a JSON array and executing the corresponding command
352 | """
353 | while True:
354 | line = []
355 | while True:
356 | lines = sys.stdin.read(1)
357 | line.append(lines)
358 | if lines == "\n":
359 | break
360 | a = "".join([str(item) for item in line])
361 | nodesdtin = json.loads(a)
362 | if nodesdtin[0] == "newConnection":
363 | sys.stdout.write(f"{json.dumps(newConnection(nodesdtin[1], nodesdtin[2]))}EOF")
364 | sys.stdout.flush()
365 | elif nodesdtin[0] == "executeQuery":
366 | sys.stdout.write(f"{json.dumps(executeQuery(nodesdtin[1], nodesdtin[2]))}EOF")
367 | sys.stdout.flush()
368 | elif nodesdtin[0] == "fetchall":
369 | sys.stdout.write(f"{json.dumps(fetchall(nodesdtin[1], nodesdtin[2]))}EOF")
370 | sys.stdout.flush()
371 | elif nodesdtin[0] == "fetchmany":
372 | sys.stdout.write(f"{json.dumps(fetchmany(nodesdtin[1], nodesdtin[2], nodesdtin[3]))}EOF")
373 | sys.stdout.flush()
374 | elif nodesdtin[0] == "fetchone":
375 | sys.stdout.write(f"{json.dumps(fetchone(nodesdtin[1], nodesdtin[2]))}EOF")
376 | sys.stdout.flush()
377 | elif nodesdtin[0] == "executeMany":
378 | sys.stdout.write(f"{json.dumps(executeMany(nodesdtin[1], nodesdtin[2]))}EOF")
379 | sys.stdout.flush()
380 | elif nodesdtin[0] == "executeScript":
381 | sys.stdout.write(f"{json.dumps(executeScript(nodesdtin[1]))}EOF")
382 | sys.stdout.flush()
383 | elif nodesdtin[0] == "load_extension":
384 | sys.stdout.write(f"{json.dumps(load_extension(nodesdtin[1]))}EOF")
385 | sys.stdout.flush()
386 | elif nodesdtin[0] == "backup":
387 | sys.stdout.write(f"{json.dumps(backup(nodesdtin[1], nodesdtin[2], nodesdtin[3], nodesdtin[4]))}EOF")
388 | sys.stdout.flush()
389 | else:
390 | sys.stdout.write(f"{json.dumps('Error: Invalid command')}EOF")
391 | sys.stdout.flush()
392 |
393 |
394 | main()
395 |
--------------------------------------------------------------------------------