Git Product home page Git Product logo

ngorm's Issues

Try goa

Goa is a code generator that fully supports Gorm.

If you can match the postresql API then it would be great because I could use Ql on mobile and cockroaches on the server , whilst using the same code.

Probably worth putting a test with gomobile to check Ql works on android and iOS simulator.
Easiest was to test if to log to a cloud based log system like Google cloud .

Can't add an Index

Hello

I have problems to add an Index to a Model. Most likely I'm doing something wrong. I would appreciate an example of how to do it correctly.

I have found two issues:

  • Without model.Model in struct Test it can't create the the index statement, because it can't find the field deleted_at
  • The output statement contains a WHERE clause

Thank you for your help and the awesome library.

Example:

package main

import (
	"fmt"

	"github.com/ngorm/ngorm"
	"github.com/ngorm/ngorm/model"
	_ "github.com/ngorm/ql"
)

type Test struct {
	model.Model	
	Name   string
	Number int
}

func main() {
	db, err := ngorm.Open("ql-mem", "test.db")
	if err != nil {
		panic(err)
	}

	expr, err := db.Begin().AutomigrateSQL(&Test{})
	if err != nil {
		panic(err)
	}
	fmt.Println(expr.Q)

	expr, err = db.Model(&Test{}).AddIndexSQL("idx_test_number", "name", "number")
	if err != nil {
		panic(err)
	}
	fmt.Println(expr.Q)
}

Output:

BEGIN TRANSACTION;
	CREATE TABLE tests (id int64,created_at time,updated_at time,deleted_at time,name string,number int ) ;
	CREATE INDEX idx_tests_deleted_at ON tests(deleted_at);
COMMIT;
CREATE INDEX idx_test_number ON tests(name, number) WHERE  deleted_at IS NULL

Try to expose the gorm API

NGORM is not intending to be 100% API compatible with gorm. One aspect which ngorm emphasis is error handling. Errors must be handled, so any operation that might result into an error returns an error.

So, many functions should be familiar with gorm, it is just how they are implemented differs. So, this is the list of API for DB that must pe implemented by ngorm.

I discourage heavy use of chaining.Only when it is necessary to chain then chain.

  • DB.AddForeignKey
  • DB.AddIndex
  • DB.AddUniqueIndex
  • DB.Assign
  • DB.Association
  • DB.Attrs
  • DB.Automigrate
  • DB.CommonDB
  • DB.Count
  • DB.CreateTable
  • DB.Delete
  • DB.Dialect
  • DB.DropColumn
  • DB.DropTable
  • DB.DropTableIfExests
  • DB.Find
  • DB.First
  • DB.FirstOrCreate
  • DB.FirstOrInit
  • DB.Group
  • DB.HasTable
  • DB.Having
  • DB.Set
  • DB.Joins
  • DB.Last
  • DB.Limit
  • DB.Model
  • DB.ModifyColumn
  • DB.Not
  • DB.Offset
  • DB.Omit
  • DB.Or
  • DB.Order
  • DB.Pluck
  • DB.Preload
  • DB.Related
  • DB.RemoveIndex
  • DB.Save
  • DB.Select
  • DB.SingulatTable
  • DB.Table
  • DB.Update
  • DB.UpdateColumn
  • DB.UpdateColumns
  • DB.Updates
  • DB.Where

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.