Git Product home page Git Product logo

Comments (4)

philliplongman avatar philliplongman commented on August 26, 2024 1

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.

fractaledmind avatar fractaledmind commented on August 26, 2024

Can you describe the shape of your composite primary keys?

from activerecord-enhancedsqlite3-adapter.

philliplongman avatar philliplongman commented on August 26, 2024

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.

fractaledmind avatar fractaledmind commented on August 26, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.