Ruby で DB を扱うちょっとしたスクリプトを書くとき、ActiveRecord で生SQLを使うと色々捗ることが多い。 そのためのメソッドをまとめてみた。 事前準備: establish_connection 作成・更新系: execute 検索系: select_all, select_one, select_rows, select_values, select_value プレースホルダ: sanitize_sql_array 事前準備 establish_connection DBとのコネクションを確立する。'mysql2', 'postgresql', 'redshift' など様々なアダプタが使える。 以下は接続設定の一例。 [MySQL] (要 mysql2 gem) require 'active_record' config = { adapter: 'mysql2
Overview General Do Avoid Naming conventions General Tables Columns Aliasing or correlations Stored procedures Uniform suffixes Query syntax Reserved words White space Indentation Preferred formalisms Create syntax Choosing data types Specifying default values Constraints and keys Designs to avoid Appendix Reserved keyword reference Column data types SQL style guide Overview You can use this set o
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く