Skip to content

Instantly share code, notes, and snippets.

View Solution's full-sized avatar
🎯
Focusing

Patrik Tomášik Solution

🎯
Focusing
View GitHub Profile
@Solution
Solution / Regpx.h
Created November 11, 2011 20:20
My C version of preg_match()
/*
* File: Regxp.h
* Author: solution
*
* Created on 11. listopad 2011, 16:00
*/
#include <stdio.h>
#include <string.h>
#include <pcre.h>
func main() {
// init the repository based on gorm instance
repository := NewRepository(database)
// create qo from repository, you can do it again and again
qo := repository.NewQueryObject().
FilterByUsername("myUsername"). // compose your q.
FilterByActive()
// and than fetch it
type Repository struct {
database *gorm.DB
}
func NewRepository(database *gorm.DB) Repository {
return Repository{database: database}
}
func (r Repository) NewQueryObject() *QueryObject {
return NewQueryObject(r.database.Session(&gorm.Session{NewDB: true}))
func main() {
// always use new session
qo := NewQueryObject(database.Session(&gorm.Session{NewDB: true})).
FilterByUsername("myUsername").
FilterByActive()
// and now retrieve the model
var user model.User
qo.GetQuery().First(&user)
type QueryObject struct {
query *gorm.DB
}
func NewQueryObject(database *gorm.DB) *QueryObject {
return &QueryObject{query: database.Model(&User{})}
}
func (qo *QueryObject) FilterByUsername(username string) *QueryObject {
qo.query = qo.query.Where("username = ?", username)
type User struct {
gorm.Model
Firstname string
Surname string
Email string
Phone string
Password string
Role string
Active bool
type QueryObject interface {
GetQuery() *gorm.DB
}
type User struct {
gorm.Model
Username string
Firstname string
Surname string
Email string
Phone string
Password string
Role string
@Solution
Solution / DoctrineExtension.php
Last active July 3, 2019 22:16
Gedmo extension for Kdyby\Doctrine and some changes in Gedmo\DoctrineExtensions
<?php
namespace Gedmo;
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ORM\Mapping\Driver as DriverMappingORM;
use Doctrine\Common\Persistence\Mapping\Driver as DriverORM;
use Doctrine\ODM\MongoDB\Mapping\Driver as DriverMongodbODM;
use Doctrine\Common\Annotations\Reader;
use Doctrine\Common\Annotations\CachedReader;
package transportServiceClient
import (
"net/http"
"strconv"
"fmt"
)
type Client struct {
*client.Client