Alpha Chen 1 year ago
parent 94dc7b5796
commit 50dd7f1533
Signed by: alpha
SSH Key Fingerprint: SHA256:3fOT8fiYQG/aK9ntivV3Bqtg8AYQ7q4nV6ZgihOA20g

@ -6,6 +6,10 @@ gem "sequel"
gem "sqlite3"
group :dev do
# Manually adding IRB as a dependency so I can adjust colors until
# https://github.com/ruby/reline/pull/552 is in Ruby itself
gem "irb"
gem "minitest"
gem "rake"
end

@ -2,16 +2,28 @@ GEM
remote: https://rubygems.org/
specs:
bigdecimal (3.1.4)
io-console (0.6.0)
irb (1.9.0)
rdoc
reline (>= 0.3.8)
minitest (5.20.0)
psych (5.1.1.1)
stringio
rake (13.0.6)
rdoc (6.6.0)
psych (>= 4.0.0)
reline (0.4.0)
io-console (~> 0.5)
sequel (5.73.0)
bigdecimal
sqlite3 (1.6.8-arm64-darwin)
stringio (3.0.9)
PLATFORMS
arm64-darwin-22
DEPENDENCIES
irb
minitest
rake
sequel

@ -0,0 +1,15 @@
Sequel.migration do
change do
alter_table(:notes) do
add_primary_key :id
end
alter_table(:sources) do
add_primary_key :id
end
alter_table(:titles) do
add_primary_key :id
end
end
end

@ -1,13 +1,13 @@
require_relative "../models"
module Alphadex
def self.add_bookmark(url, title, note, tags)
def self.add_bookmark(url:, title:, note:, tags:)
fail "url already exists" unless Url.where(url:).empty?
DB.transaction do
entity = Entity.create
entity.url = Url.new(url:)
entity.title = Title.new(title:)
entity.title = Title.new(title:) if title
entity.add_note(text: note)
tags.map { Tag.find_or_create(name: _1) }.each do |tag|
entity.add_tag(tag)

@ -4,6 +4,7 @@ require_relative "db"
Sequel::Model.plugin :timestamps
module Alphadex
class Entity < Sequel::Model
one_to_many :notes
one_to_many :sources
@ -11,6 +12,7 @@ class Entity < Sequel::Model
many_to_many :tags
one_to_one :url
# override this since I have `created_at` on this join table for some reason
def add_tag(tag)
DB[:entities_tags].insert(entity_id: self.id, tag_id: tag.id, created_at: DateTime.now)
end
@ -34,5 +36,6 @@ class Tag < Sequel::Model
end
class Url < Sequel::Model
one_to_one :entity
many_to_one :entity
end
end

Loading…
Cancel
Save