Giter VIP home page Giter VIP logo

topaz's People

Contributors

danielpclark avatar tbrand avatar zhomart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

topaz's Issues

Add `persisted?` method

I'd like to check if a model is persisted. It will help with validations later too.

class Thing < Topaz::Model
  columns(
    description: String
  )
end

x = Thing.new("a")
x.persisted?
# => false
x.save
x.persisted?
# => true

y = Thing.create("b")
y.persisted?
# => true

DB.open on each save?

Is a DB connection opened on each save? Opening a connection is really, really slow. It should be done once in your application. I'm talking about these lines.

I've made a benchmark:

require "benchmark"
require "pg"

DB.open "postgres:///" do |db|
  db.exec "drop table if exists contacts"
  db.exec "create table contacts (num integer)"
end

shared_db = DB.open "postgres:///"

Benchmark.ips do |x|
  x.report("open each time") do
    DB.open "postgres:///" do |db|
      db.exec "insert into contacts (num) values (1)"
    end
  end
  x.report("open once") do
    shared_db.exec "insert into contacts (num) values (1)"
  end
end

Results:

open each time  73.53  (  13.6ms) (± 4.26%) 58.82× slower
     open once   4.32k (231.23µs) (± 1.68%)       fastest

Almost 60 times slower to open and close a connection each time.

I'm not sure, but it could be the reason why you don't get very good performance here

Integration with micrate?

This is more a suggestion than an issue itself, I was just wondering if you guys are considering integrate Topaz with micrate for handling database migrations.

From all the ORM that I have been evaluating, I really like Topaz because for its simplicity but I feel that the way Topaz handles migrations will be not enough for large-scale projects.

Thanks

TravisCI is failing to fetch sqlite3

We may need to update the dependency builds for TravisCI

Get:1 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 libsqlite3-dev amd64 3.7.15.1-1~travis1 [582 kB]
Err:1 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 libsqlite3-dev amd64 3.7.15.1-1~travis1
  Hash Sum mismatch
Get:2 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 libsqlite3-0 amd64 3.7.15.1-1~travis1 [459 kB]
Err:2 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 libsqlite3-0 amd64 3.7.15.1-1~travis1
  Hash Sum mismatch
Get:3 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 sqlite3 amd64 3.7.15.1-1~travis1 [122 kB]
Err:3 http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu precise/main amd64 sqlite3 amd64 3.7.15.1-1~travis1
  Hash Sum mismatch
Fetched 1,163 kB in 2s (572 kB/s)
E: Failed to fetch http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu/pool/main/s/sqlite3/libsqlite3-dev_3.7.15.1-1~travis1_amd64.deb  Hash Sum mismatch
E: Failed to fetch http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu/pool/main/s/sqlite3/libsqlite3-0_3.7.15.1-1~travis1_amd64.deb  Hash Sum mismatch
E: Failed to fetch http://ppa.launchpad.net/travis-ci/sqlite3/ubuntu/pool/main/s/sqlite3/sqlite3_3.7.15.1-1~travis1_amd64.deb  Hash Sum mismatch
E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
The command "sudo apt-get install sqlite3=3.7.15.1-1~travis1" failed and exited with 100 during .
Your build has been stopped.

This is causing all tests to fail (and not even run).

Time format and Postgres

After some testing and experimenting it looks like the default time format in the base Model class doesn't play nice with PG.

https://github.com/topaz-crystal/topaz/blob/master/src/topaz/model.cr#L9

Example using a sample table:

sampledb> insert into sample_table (name, created_at, updated_at) 
  values ('sdf', '2017-03-05 08:43:37.681', '2017-03-05 08:43:37.681');
INSERT 0 1
Time: 0.022s


sampledb> insert into sample_table (name, created_at, updated_at)
  values ('sdf', '2017-03-05 08:43:37:681', '2017-03-05 08:43:37:681');

invalid input syntax for type timestamp: "2017-03-05 08:43:37:681"
LINE 1: ...me, created_at, updated_at) values ('sdf', '2017-03-0...

First example using the period. Second example using the colon.

I overridded it in my own project's base model class and that looks like it works fine

require "topaz"

class SampleTable < Topaz::Model
  TIME_FORMAT = "%F %T.%L %z"

Update via JSON

How do you update an existing model from JSON? I can't seem to figure out the use of from_json and update with this.

Default values?

Say I want to have a default value for a model schema. Let's use a Todo app as an example:

class Todo < Topaz::Model
  columns(
    description: String,
    completion: Time?
  )
end

The completion parameter should be assumed to be nil if no value is given unless nullable: false has be set as in https://github.com/topaz-crystal/topaz/blob/master/spec/model/models.cr#L48.

So if the union has a type of Nil in it I'd like the parameters in the create method to have = nil in it by default. Again, to avoid that I'd use nullable: false.

As far as other default values I'm not sure how you'd want to do it. Maybe something like?

class Todo < Topaz::Model
  columns(
    description: String, {default: ""},
    attempts: Int32, {default: 0}
  )
end

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.