Skip to content

Instantly share code, notes, and snippets.

@noam-honig
noam-honig / InnerSelectHelper.cs
Last active March 13, 2025 05:26
Inner Select Helper With Child Rows
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Firefly.Box;
using Firefly.Box.Data.Advanced;
using ENV.Data.DataProvider;
using Firefly.Box.Data.DataProvider;
@noam-honig
noam-honig / filterContains.ts
Created October 11, 2024 07:11
A way to test if an EntityFilter contains a field #remult
/**
* Checks if a filter contains a specific field
* @example
backendPreprocessFilter: async (filter) => {
// If not specific filter for deletedBy was specified - only show non deleted rows
if (!filterContains(filter, 'deletedBy')) {
return {
...filter,
deletedBy: null,
}
dataProvider: async () => {
const result = await createKnexDataProvider({
client: 'mssql',
//debug: true,
connection: {
server: process.env['DBServer'],
database: process.env['DBDatabase'],
user: process.env['DBUser'],
password: process.env['DBPassword'],
query_timeout: 30000,
@noam-honig
noam-honig / bulk-insert.ts
Last active September 11, 2024 13:02
bulk insert without hooks - just push to sql db
async function bulkInsert<entityType extends EntityBase>(
array: entityType[],
db: SqlDatabase,
) {
if (array.length == 0) return
const chunkSize = 250
for (let i = 0; i < array.length; i += chunkSize) {
const items = array.slice(i, i + chunkSize)
@noam-honig
noam-honig / data-provider-wrapper.ts
Last active September 11, 2024 12:59
DataProvider wrapper that documents number of returned rows and query duration
return new Proxy(db, {
get(target, prop) {
if (prop == 'getEntityDataProvider') {
return (meta: EntityMetadata) => {
return new Proxy(db.getEntityDataProvider(meta), {
get(target, prop) {
if (prop == 'find') {
return async (options: EntityDataProviderFindOptions) => {
const start = performance.now();
const result = await target.find(options);
@noam-honig
noam-honig / changelog.ts
Created April 21, 2024 14:52
Chagelog / audit trail
import {
Entity,
FieldRef,
Fields,
FieldsRef,
getEntityRef,
IdEntity,
isBackend,
LifecycleEvent,
@noam-honig
noam-honig / todo tutorual simple css
Created October 2, 2022 10:29
todo tutorual simple css
body {
font-family: Arial, Helvetica, sans-serif;
background-color: #f5f5f5;
display: flex;
justify-content: center;
font-size:x-large
}
input{
font-size: x-large;
min-width: 18px;
@noam-honig
noam-honig / gist:4621f19e66b3448aff30c0485be985cb
Last active December 13, 2021 14:53
dynamically load entities
import glob from 'glob';
import path from 'path';
for (const type of ["entity", "controller"]) {
for (const ext of ["js", "ts"]) {
for (const file of glob.sync(`src/**/*.${type}.${ext}`)) {
require(path.resolve(file))
}
}
}
@noam-honig
noam-honig / generate-test-data.sql
Created November 30, 2021 04:05
Anonymize relational data Sql Scripts
create table Person(
social_security_number int,
name varchar(50)
)
create table transactions(
person_social_security_number int,
month int,
amount decimal
)
@noam-honig
noam-honig / .gitignore
Created October 20, 2021 10:49
Basic typescript express sttartup project
# See http://help.github.com/ignore-files/ for more about ignoring files.
# compiled output
/dist
/tmp
/out-tsc
# Only exists if Bazel was run
/bazel-out
# dependencies