https://github.com/pingcap/activerecord-tidb-adapter
目前已经兼容 ActiveRecord,之后后添加 TiDB 特有的 feature,欢迎测试反馈
现在 GitHub 的正确打开姿势是这个 :https://github.dev/pingcap/activerecord-tidb-adapter (官方)
官方功能,看私人 repo“感觉”更加安全了。
在 repo 页面点击 .
,就能进入 web 版 vs code。
体验了创建分支、改文件、提交、创建 pr、浏览 pr、评审 pr,十分流畅。更重要的是还支持 vs code 的快捷键!
彩蛋:在 pr 页面也可以通过点击.
进入 vs code 模式,评审大 pr 的时候实在是太方便了
增加了 sequence 支持:
Sequence as primary key
class TestSeq < ActiveRecord::Migration[6.1]
def up
# more options: increment, min_value, cycle, cache
create_sequence :orders_seq, start: 1024
create_table :orders, id: false do |t|
t.primary_key :id, default: -> { "nextval(orders_seq)" }
t.string :name
end
end
def down
drop_table :orders
drop_sequence :orders_seq
end
end
Generated DDL
mysql> show create table orders_seq\G;
*************************** 1. row ***************************
Sequence: orders_seq
Create Sequence: CREATE SEQUENCE `orders_seq` start with 1024 minvalue 1 maxvalue 9223372036854775806 increment by 1 nocache nocycle ENGINE=InnoDB
mysql> show create table orders\G;
*************************** 1. row ***************************
Table: orders
Create Table: CREATE TABLE `orders` (
`id` bigint(20) NOT NULL DEFAULT nextval(`activerecord_tidb_adapter_demo_development`.`orders_seq`),
`name` varchar(255) COLLATE utf8mb4_general_ci DEFAULT NULL,
PRIMARY KEY (`id`) /*T![clustered_index] CLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci
This gem also adds a few helpers to interact with SEQUENCE
# Advance sequence and return new value
ActiveRecord::Base.nextval("numbers")
# Return value most recently obtained with nextval for specified sequence.
ActiveRecord::Base.lastval("numbers")
# Set sequence's current value
ActiveRecord::Base.setval("numbers", 1234)