控制台访问模型
来源:互联网 发布:网络空间安全考研排名 编辑:程序博客网 时间:2024/05/18 22:15
控制台访问模型
rails console 简写为 rails c
rails dbconsole 或者 rails db 直接连接数据库
新增记录:
模型类.new -> 模型实例变量.save2.1.5 :001 > p = Post.new(:title => "My First Post", :context=>"this is my first post") => #<Post id: nil, title: "My First Post", context: "this is my first post", created_at: nil, updated_at: nil>2.1.5 :002 > p.save() (0.5ms) begin transaction SQL (0.7ms) INSERT INTO "posts" ("context", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["context", "this is my first post"], ["created_at", "2014-12-03 11:44:50.954572"], ["title", "My First Post"], ["updated_at", "2014-12-03 11:44:50.954572"]] (23.0ms) commit transaction => true
模型类.create
2.1.5 :003 > Post.create(:title => "create test", :context=>"test of create") (0.2ms) begin transaction SQL (0.4ms) INSERT INTO "posts" ("context", "created_at", "title", "updated_at") VALUES (?, ?, ?, ?) [["context", "test of create"], ["created_at", "2014-12-03 11:48:08.779270"], ["title", "create test"], ["updated_at", "2014-12-03 11:48:08.779270"]] (21.9ms) commit transaction => #<Post id: 2, title: "create test", context: "test of create", created_at: "2014-12-03 11:48:08", updated_at: "2014-12-03 11:48:08"> ```>查询记录
模型类.all
2.1.5 :004 > posts = Post.all
Post Load (0.6ms) SELECT “posts”.* FROM “posts”
=> #
>更新记录
模型实例变量.update -> 模型实例变量.save()2.1.5 :008 > post.title = "test update" => "test update"2.1.5 :009 > post.save() (0.4ms) begin transaction SQL (1.2ms) UPDATE "posts" SET "title" = ?, "updated_at" = ? WHERE "posts"."id" = 2 [["title", "test update"], ["updated_at", "2014-12-03 11:57:08.964494"]] (10.0ms) commit transaction => true模型实例变量.update_attribute(field,value)2.1.5 :010 > post.update_attribute(:context,"test operation of update_attribute") (0.4ms) begin transaction SQL (1.4ms) UPDATE "posts" SET "context" = ?, "updated_at" = ? WHERE "posts"."id" = 2 [["context", "test operation of update_attribute"], ["updated_at", "2014-12-03 12:01:12.051869"]] (32.3ms) commit transaction => true模型实例变量.update_attributes(hash)2.1.5 :013 > post.update_attributes(:title=>"test update_attribute 2", :context =>"content for test of update_attribute 2") (1.4ms) begin transaction SQL (1.2ms) UPDATE "posts" SET "context" = ?, "title" = ?, "updated_at" = ? WHERE "posts"."id" = 2 [["context", "content for test of update_attribute 2"], ["title", "test update_attribute 2"], ["updated_at", "2014-12-03 12:05:16.878764"]] (26.1ms) commit transaction => true
删除记录
模型实例变量.destroy2.1.5 :016 > post.destroy (0.3ms) begin transaction SQL (1.3ms) DELETE FROM "posts" WHERE "posts"."id" = ? [["id", 2]] (23.6ms) commit transaction => #<Post id: 2, title: "test update_attribute 2", context: "content for test of update_attribute 2", created_at: "2014-12-03 11:48:08", updated_at: "2014-12-03 12:05:16">
0 0
- 控制台访问模型
- WebLogic:访问管理控制台
- 控制台宿主 公网访问
- 修改weblogic控制台访问端口
- 修改weblogic控制台访问端口
- weblogic禁止访问控制台问题
- 对象的访问模型
- 访问控制模型
- windows 访问控制模型
- 访问控制模型综述
- 访问匿名模型
- SOCKET访问基本模型
- python-访问模型
- OpenGL + vc6.0 控制台实现《太阳系模型》
- 控制台应用程序访问SharePoint对象的注意事项
- android学习笔记---控制台访问SQLite
- C#控制台 访问基类被屏蔽的方法
- C#访问剪切板,兼容控制台和web
- 秒杀后台系统设计
- 在vue项目中前端生成二维码应该注意的问题
- 随机产生一个整数
- android 二维码 Zxing记录
- 自定义视频播放(原生)
- 控制台访问模型
- Volume of Mesh Calculation With WebGL
- missing artifact jdk.tools:jar:1.7
- linux shell 中的sleep命令
- STM32在KEIL4.7下生成BIN文件
- Android AlarmManager实现不间断轮询服务
- Memcached 笔记与总结(6)PHP 实现 Memcached 的一致性哈希分布算法
- iOS开发内存优化-问题代码定位
- dismissViewControllerAnimated到根视图