This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @BindingAnnotation(BindPost.PostBinderFactory.class) | |
| @Retention(RetentionPolicy.RUNTIME) | |
| @Target({ElementType.PARAMETER}) | |
| public @interface BindPost { | |
| class PostBinderFactory implements BinderFactory { | |
| public Binder build(Annotation annotation) { | |
| return new Binder<BindPost, Post>() { | |
| public void bind(SQLStatement q, BindPost bind, Post post) { | |
| Array array = q.getContext().getConnection().createArrayOf("varchar", post.getTags()); | |
| q.bind("title", post.getTitle()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Mapping a string array to `varchar[]` in Postgres | |
| String[] tags = ... | |
| Array array = q.getContext().getConnection().createArrayOf("varchar", tags); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * name - column name | |
| * value - data to be bind to column | |
| * sqlType - SQL data type to map to | |
| */ | |
| bindBySqlType(String name, Object value, int sqlType) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @SqlUpdate("INSERT INTO posts(title, tags) VALUES (:title, :tags)") | |
| int createPost(@Bind("title") String title, @Bind("tags") List<String> tags); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| CODE_PATH = "/path/to/repos" | |
| RUN_PATH = Dir.pwd | |
| IGNORED_DIRS = [".", "..", "temp", "dont-search-in-here"] | |
| Dir.entries(CODE_PATH).select do |f| | |
| begin | |
| if !IGNORED_DIRS.include? f | |
| Dir.chdir("#{CODE_PATH}/#{f}") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mongo> db.sequences.find().pretty() | |
| { | |
| "key": "orders", | |
| "counter": 3 | |
| }, | |
| { | |
| "key": "favorites", | |
| "counter": 15 | |
| }, | |
| ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * processOrder(...); // orderNumber => 1 | |
| * processOrder(...); // orderNumber => 2 | |
| * ... | |
| */ | |
| public Order processOrder(...) { | |
| long orderNumber = getNext("orders"); | |
| return createOrder(orderNumber, ...); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Assuming an entity class called 'Sequence' has been created to | |
| * represent the sequence collection | |
| **/ | |
| public long getNext(String collection) { | |
| Sequence seq = datastore.findAndModify( | |
| datastore.find(Sequence.class, "key = ", collection), // query | |
| datastore.createUpdateOperations(Sequence.class).inc("counter") // update | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "key": "orders", | |
| "counter": 0 | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val registerForm = Form( | |
| mapping( | |
| "email" -> nonEmptyText.verifying(emailCheckConstraint), | |
| "password" -> nonEmptyText.verifying(passwordCheckConstraint), | |
| "cities" -> optional(list(text)), | |
| "other_city" -> optional(text) | |
| )(RegisterForm.apply)(RegisterForm.unapply).verifying(citiesCheckConstraint) | |
| ) |