Comments (5)
Try using :autoincrement
instead of :auto_increment
. It's spelled as AUTOINCREMENT in SQLite. Unfortunately it looks like it's spelled as AUTO_INCREMENT in MySQL and PostgreSQL, so this all depends on the backend. I wasn't aware of this issue until now, but I'm interested in fixing it sometime since I want the different backends fairly normalized. I don't know what the SQL standard specifies for the spelling (generally what PostgreSQL does), if it's even standardized at all.
Just in case you didn't know, you can use the emacsql-show-last-sql
command to examine the SQL query sent to the backend.
CREATE TABLE IF NOT EXISTS info (id &INTEGER PRIMARY KEY
AUTOINCREMENT, node &TEXT, contents &TEXT UNIQUE);
That should help in debugging this sort of issue. The &
tokens will be replaced with the backend's specific types.
from emacsql.
Actually, the problem is not exactly syntactical. Latest version of MySQL (MariaDB) will recognize UNIQUE
in column definition as valid syntax (a more traditional way in MySQL is to write the constraints after column definitions, as if they were separate columns).
The problem is that unless you specify the minimum length for the field, e.g. varchar(100)
, MySQL cannot make it unique (in order to make it unique, it needs to build an index, and in order to do that, it needs to know the size of the field). So, if, instead of &TEXT
I could put &VARCHAR(100)
, that would have worked too.
from emacsql.
Ah, gotcha, you were already ahead of me on this. Currently EmacSQL uses LONGTEXT for "object" columns in MySQL. I hadn't planned for types to be this fine-tuned on a per-column basis, just on a per-connection-class basis. Perhaps the schema s-exp syntax could be extended to support custom types? I'm thinking maybe if a string is present in the column specifier list in place of a type (so immediately after the column name), the content of the string is coped in literally for these special situations.
[:create-table :if :not :exists info
([(id integer :primary-key :auto_increment)
(node object)
(contents "varchar(100)" :unique)])]))
What do you think of that?
from emacsql.
I may be overthinking it, but here's what I think: From what I see, you are caching the queries, and the "problem" with strings is that in Emacs they are mutable. This is definitely not a huge problem if you are careful, still, symbols are better for this. Another concern is that if this type repeats very often, an obvious optimization would be to try to use a variable instead of a literal string.
I also see that the expression parser implements something similar to define-syntax
(a Scheme way to deal with macros), so why not try to extend the parser by reserving a symbol, or a convention, which, when matched, would call back to the user code with the AST node currently being generated and the original data the user put in there, something like: [(sql (unique-constraint contents (varchar 100))) ...]
where (sql ...)
form would call back to unique-constraint
with arguments 'contents
and '(varchar 100)
and would try to incorporate the result back into the statement being build?
from emacsql.
(I don't claim to have understood everything that was said above.)
We decided a long time ago to stick to storing everything (except nil
) as a read
able string, regardless of whether that was a good early design decision or not.
I have taken over as the maintainer of this package because there are several popular packages (including some of mine), which use a SQLite backend. I have decided to keep support for PostgreSQL and MySQL, just in case someone (still) uses EmacSQL with such a back-end, but the focus is on SQLite and I do not plan to invest any time improving other back-ends.
I hope you are fine with me closing this issue.
from emacsql.
Related Issues (20)
- Comma syntax / How to use :set for multiple columns? HOT 1
- Test failure in emacsql-nul-character on Emacs 25 HOT 1
- MELPA recipe fails without "next" branch HOT 2
- "apply: Selecting deleted buffer" when opening a magit buffer (with forge installed) HOT 5
- Can't get past `(invalid-read-syntax "#" 37 73)` HOT 5
- magit-status initially fails with "process emacsql-sqlite no longer connected to pipe; closed it" HOT 4
- emacsql error on install with use package from melpa: Symbol’s value as variable is void: emacsql-sqlite-reserved HOT 5
- Test all back-ends HOT 3
- SQLite binary fails to compile (via spacemacs/magit/forge) HOT 1
- Missing sqlite subdirecotory in melpa HOT 3
- emacsql-process does not return a process on the built-in connection HOT 2
- Preparing to release 4.0.0 HOT 10
- does :with :as :values work? HOT 1
- Incorrect argument to malloc HOT 2
- Timeout trying to open sqlite db on m1 Mac HOT 3
- how to query based on time-stamp? HOT 1
- emacsql-sqlite failing (timeout, still running) on OS X (Big Sur) HOT 14
- 'No EmacSQL SQLite binary available, aborting' after building from master HOT 1
- Update vendored SQLite HOT 2
- "url" and "url-http" seem never used in emacsql-sqlite.el
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from emacsql.