Comments (4)
Yes and no.
It's an experimental project. I'm playing with making a graph db implementation for the LiteStack.
I wanted to use a composite key instead of an index because it means the rows will be stored together. I realize the performance gains to read speeds would probably be tiny, even for a very big SQLite db—but I figured the performance hit on write speeds would be similarly negligible, and I had an inkling that it would be useful down the line.
Since it's proving difficult to implement, it's probably not worth the trouble. I'll most likely drop the idea and go back to using a unique index, as you suggest.
from activerecord-enhancedsqlite3-adapter.
Can you describe the shape of your composite primary keys?
from activerecord-enhancedsqlite3-adapter.
Here's the schema as it currently stands. I'd like nodes.id
to increment.
ActiveRecord::Schema[7.1].define(version: 2023_09_28_231239) do
create_table "links", primary_key: ["type", "source_id", "target_id", "metadata"], force: :cascade do |t|
t.text "type", null: false
t.integer "source_id", null: false
t.integer "target_id", null: false
t.json "metadata", default: {}
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["source_id"], name: "index_links_on_source_id"
t.index ["target_id"], name: "index_links_on_target_id"
end
create_table "nodes", primary_key: ["type", "id"], force: :cascade do |t|
t.text "type", null: false
t.integer "id", null: false
t.json "data", default: {}, null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_foreign_key "links", "nodes", column: "source_id"
add_foreign_key "links", "nodes", column: "target_id"
end
from activerecord-enhancedsqlite3-adapter.
That's what I worried was the case. We can't add an auto_increment
option to individual columns. SQLite only supports auto-increment on a integer primary key column:
AUTOINCREMENT is not allowed on any table column other than INTEGER PRIMARY KEY. Any attempt to use AUTOINCREMENT on a column other than the INTEGER PRIMARY KEY column results in an error.
— https://www.sqlite.org/autoinc.html
Are you certain you need a composite PRIMARY KEY? What about simply adding a UNIQUE INDEX on the set of columns (see: https://stackoverflow.com/a/6154876/2884386)?
from activerecord-enhancedsqlite3-adapter.
Related Issues (11)
- Using this gem in another rails gem for testing
- `bin/rails db:prepare` breaks virtual/generated columns in `db/schema.rb` HOT 2
- Compatibility with sqlite3 v2? HOT 3
- Unable to run db:migrate HOT 9
- corrupting disk image HOT 8
- ActiveRecord::ReadOnlyError: Write query attempted while in readonly mode: UPDATE HOT 1
- Interaction with litestack? HOT 2
- Safety level may not be changed inside a transaction HOT 6
- Enabling isolate_connection_pools throws error. HOT 3
- Compatibility with Rails 7.2
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 activerecord-enhancedsqlite3-adapter.